Unit 1
Unit 1
Unit 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.
----------------
---------------- Global
data
----------------
----------------
Program
Global
data
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
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.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++.
Ramesh