Вы находитесь на странице: 1из 6

Object Oriented Programming 1

UNIT
1

OBJECT ORIENTED
THINKING

Syllabus:
Object oriented thinking: Need for oop paradigm, A way of viewing world – Agents,
responsibility, messages, methods, classes and instances (Inheritance), method
binding, overriding and exceptions, summary of oop concepts, coping with
complexity, abstraction mechanisms.

Ramesh
Object Oriented Programming 2
1. 1 Different Strategies for Problem Solving: -
The problem solving strategies are

1. Monolithic programming
2. Procedural programming
3. Structured Programming
4. Object oriented programming.

1.1.1 Monolithic Programming: - Global data is shared by the entire program


without any subprograms concept is called as monolithic programming. Traditional
BASIC is the best example for monolithic programming.

----------------

---------------- Global
data
----------------

----------------

Program

1.1.2 Procedural Programming: - To solve a big problem, it is better to divide into


smaller pieces and then start solving it is a key fact behind procedural
programming. Large programs and each sub program is responsible for solving a
particular task of the main problem. All these sub programs are usually share the
global data. COBOL is the best example for procedural programming.

Global
data

---------------- ---------------- ----------------


---------------- ---------------- ----------------
---------------- ---------------- ----------------
---------------- ---------------- ----------------

subprogram subprogram subprogram

Ramesh
Object Oriented Programming 3
1.1.3 Structured Programming: - Grouping of related tasks into single unit is
called module, group of these modules solve the large program. This concept is base
for structured programming. These modules will share global data. Pascal and C
programming languages are examples for structured programming.

Global
data

Module A Module B Module C

If we closely observe monolithic, procedural, and structured programming


methodologies, we can identify a common factor that is global data. In monolithic
programming languages the entire program shares global data. In structural
programming language, modules share the global data. There is no restriction on
this global data. Global data is freely moves throughout all the modules or sub
programs. This was major drawbacks of all these programming languages.
1.1.4 Object Oriented Programming:
A new way of problem solving technique is object oriented programming.
According some authors difference between procedures oriented and object oriented
is very simple, which is shown in the following equation.
Algorithms + Data = POPS
Data + Algorithms = OOPS

1.2 Need for OOP Paradigm: Object oriented programming (OOP), as the name
suggests, is a paradigm where we focus real life objects while programming any
solution. By focusing real life objects we mean that over solutions revolves around
different objects, which represent respective objects in real life situation. We not
only write programs to process data, we actually write behaviours of our
programming objects, those behaviours are called methods in objected oriented
programming. The data elements on which those objects behave, are called data-
members/fields.
In a more in-depth view towards OOP using domain specific terminology, following
are the fundamental features we get:

Ramesh
Object Oriented Programming 4
Encapsulation
Inheritance
Re-usability
Information Hiding

Encapsulation:
The way we make a logical boundary around behaviours (methods) and data
(properties) they work on is called Encapsulation.

Inheritance:
As in real life, objects in OOP relate to each other in one way or another, the
relationship in most of the case is parent/child relationship. The child objects
inherent all the functionalities (methods) and data (properties) of their parents.

Re-usability
Along with inheritance, some other phenomena like method overloading and
overriding, provide code-reuse, which is known to be a very basic feature of object
oriented programming.

Information Hiding
When we have ways to reuse our code through one way or other, we are also in
need of some security regarding our source code. To protect it from unauthorized
access/ alteration. In object oriented programming, this is called Information
Hiding and is achieved through "Access Modifiers" which lets us restrict access to
all or some parts of our objects methods and/or data.

1.3 OOP’s Principles: -


The Concepts are
1. Class
2. Object
3. Data Abstraction
4. Data Encapsulation
5. Inheritance
6. Polymorphism
7. Message Passing
8. Persistence
9. Delegation
10. Genericity

1.3.1 Class: - It is a user defined data type, which holds both data and
functions(methods). This data is called member data and functions are called
member functions or methods.
Syntax: class classname
{
private member data;
member functions;

Ramesh
Object Oriented Programming 5
public member data;
member functions;
protected member data;
member functions;
};
Rules: -
1. The key word ‘class’ specifies the class name. The body of a class is enclosed
within braces and terminated by a semicolon.
2. The body of a class consists of a variable and functions. These variable and
functions are called “members”.
3. The members that have been declared as “private” can be accessed only from
within the class.
4. The members that have been declared as a “public” can be accessed from
outside the class also.
5. The members that have declared as a “protected”, as non member function
are concerned, “private” are one and the same, but member functions in base
class can access the unction from “protected”.
1.3.2 Object: - An Object is an instance of a class. An object is any real world
entity, which is having state, identity and behavior. State represents current
condition of the object, identity refers to how it differs from similar kind of object
and behavior tells the working principle of the particular object.
1.3.3 Data Abstraction: - The essential characteristics of an object that distinguish
it from all other kind of object are called data abstraction. With the help of data
abstraction we can create new data types that are suitable for application. Class is
used for creating user defined data type is called Abstract Data Type (ADT). The
data types created by data abstraction process are known as ADT.
1.3.4 Data Encapsulation: - The wrapping up of data and methods into a single
unit (class) is known as Encapsulation. Combination of data and its related methods
is called encapsulation.
Encapsulation = Data + Operations
(or)
Encapsulation = [private] Data + [public] Operations
1.3.5 Inheritance: - It is used to acquire the properties of an existing class into a
new class. Extending an existing class is called Inheritance. A class, which inherits
it properties, is known as Base class (generic class) and a class into which these
properties are inherited is known as a derived class (specialized class). Concept of
inheritance is also known as Class Hierarchy.
There are various types of inheritances, they are
1. Single Inheritance 2.Multiple Inheritance 3.Multilevel Inheritance
4. Hierarchical Inheritance 5. Multipath Inheritance 6.Hybrid Inheritance
1.3.6 Polymorphism: - poly represents ‘many’ and morph represents ‘forms’. Many
forms of an entity called Polymorphism. There are two types of polymorphism.
1. Compile time polymorphism 2. Runtime polymorphism
In compile time polymorphism, the most appropriate member function is called by
compiling the type and the number of arguments at the compile time by the
compiler. It is also called Early Binding or Static Binding.

Ramesh
Object Oriented Programming 6
Ex: Function Overloading (Method Overloading)
In runtime polymorphism the most appropriate member function is called by the
compiler the run time. It is also known as Late Binding or Dynamic Binding.
Ex: Dynamic Method Dispatch.
1.3.7 Message Passing: - Process of invoking an operation of an object is called
Message Passing. In response to the given message the respective method or
operation is invoked.
1.3.8 Delegation: -Communication between two objects is made possible through
delegation. Here two objects are involved in handling request, one object delegates
operations to its delegate. Delegation is realized with the help of object composition.
The relationship between these two objects is called as has a relationship of
container ship.
1.3.9 Persistence: - Storing the details of further retrieval is called as persistence.
Object data outlives the program execution time and exists between executions of a
program. An object is called persistence object that exists after the process or
thread that created it has ceased to exist.
1.3.10 Genericity: - Technique for defining methods or classes that have more
than one interpretation depending on the data type of parameters is called
Genericity. Templates are helpful creating generic programming in C++.

1.4 Advantages of OOP:


1. OOP uses objects in programming languages.
2. The independence of each object easily to development and maintenance of the
program.
3. Data Hiding and Data Abstraction increase reliability and helps the programmer
to built secure programs.
4. Dynamic Binding increases flexibility by permitting the addition of new class
objects without having to modify the existing code.
5. Inheritance with Dynamic Binding enhance the reusability of code.

1.5 Applications of OOP:


1. Simulation and Modeling
2. User Interface Design
3. Artificial Intelligence and Expert Systems
4. Neural Networks
5. Web Designing
6. CAD/CAM system.

Ramesh

Вам также может понравиться