3. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 3
Object
Objects are the basic run-time entities in an OOP
environment.
They may represent:
a person,
a place,
a bank account or
any item that the program has to handle.
Objects are simply variables of type class. Or In pure OOP
terms an object is an instance of a user defined data type
class.
4. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 4
Object
As the name object-oriented implies, objects are key to
understand object-oriented technology.
You can look around you & can see many examples of
real-world objects:
your cell phone,
your dog,
your television set,
your car.
5. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 5
Object
All these real-world objects share two characteristics:
they all have state
and they all have behaviour
6. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 6
Real-World Objects
A Real World Object : Dog
have state like
1. Name,
2. Colour,
3. Breed
have behaviours like
1. Barking,
2. Eating
State Value
Name Tommy
Colour Brown
Breed Labrador
7. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 7
Real-World Objects
A Real World Object : Car
have state like
1. Brand,
2. Make,
3. Engine CC
have behaviours like
1. Accelerate,
2. Brake,
3. Change Gear State Value
Brand Maruti
Make Swift
Engine CC 1248 CC
8. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 8
Programmatic Objects
Software/Programmatic objects are modelled after real-
world objects in that they too have state and behaviour.
A Programmatic object : Box
have state like
Height,
Width,
Depth
have behaviours like
getDimensions()
putVolume()
9. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 9
Programmatic Objects
A Programmatic object : Bank Account
have state like
Acct No,
Acct Holder’s Name,
Current Balance
have behaviours like
Deposit(),
Withdrawal()
10. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 10
Programmatic Objects
A Programmatic object : Employee
have state like
Employee ID,
Employee Name,
Basic Salary
have behaviours like
getData(),
putSalary()
11. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 11
Programmatic Objects
Everything that the software object knows (its state) and
can do (its behaviour) is expressed by the variables and
methods within that object.
A software/programmatic object maintains:
its state in variables
implements its behaviour with methods/functions.
12. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 12
Programming Objects
Object : Student
State (Data)
RollNo
Name
M1, M2, M3
Behaviour (Functions)
getData()
putResult()
Object : Employee
State (Data)
EmpNo
Name
Basic, Ta, Da, Gross
Object : Box
State (Data)
Height
Width
Depth
Behaviour (Functions)
getDimensions()
putVolume()
Behaviour (Functions)
getData()
putSalary()
Each object contains Data and Code to manipulate that Data
Or
An object is a bundle of variables and related methods/functions.
13. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 13
Example of Objects
A software object that modelled your real-world box
would have variables that indicates the box’s current
state:
Height : 4
Width : 7
Depth : 6
The software object box would also have
methods/functions to:
getDimensions() : to take dimensions as input from user
putVolume() : to calculate and print volume of box
14. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 14
Example of Objects
A software object that modelled your real-world car
would have variables that indicates the car’s current
state:
speed : 10 mph,
pedal cadence : 90 rpm,
current gear is : 5th.
The software object car would also have
methods/functions to:
brake,
change the pedal cadence,
change gears.
15. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 15
Example of Objects
You can think of an object as a fancy variable;
it stores data and you can “make requests” to that object,
asking it to perform operations on itself.
16. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 16
Example of Objects
You can represent real-world objects using software
objects. You can represent:
real-world dog as software object in an animation program.
real-world car as a software object within a game program.
17. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 17
Class
Classes are actually special kinds of templates from which
you can create objects.
Definition : Class is a way of binding Data and its
associated Functions/Methods together.
When you define a class, you define a blueprint for an
abstract data type.
18. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 18
Class
A class is created to characterise your programmatic
object.
Everything a programmatic object knows (its state) and
can do (its behaviour) is characterised using variables and
methods defined inside the class.
A class is a logical abstract but an object has a physical
existence in the memory.
19. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 19
Abstract Data Type
Defining a Class means creating an abstract data type in
any object oriented programming language.
A data type can be called abstract, if it do not reveal its
internal implementation to the user of that type.
20. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 20
Abstract Data Type
There are 2 parts to each ADT:
The external (public) part, which consists of:
the conceptual picture (user's view of how the object looks like)
the conceptual operations (what the user can do to the ADT)
The internal (private) part, which consists of:
the representation (how the structure is actually stored)
the implementation of the operations (the actual code)
21. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 21
Abstraction
In simple words, abstraction is ‘Hiding implementation
details behind the interface’
When abstraction is created our concern is limited to
what it can do rather how it is doing it.
22. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 22
Abstraction
When we drive a car we often need to change the gears
of the vehicle but we are not concerned about the inner
details of the vehicle engine. What matters to us is that
we must shift a gear, that's it. This is abstraction
Show only those details which matters to the user.
23. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 23
Abstraction
What exactly is Hiding implementation details behind the
interface?
24. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 24
Abstraction
class box
{
private:
float h, w, d;
public:
void getDimensions()
{
cout << “Enter Height, Width & Depth : “;
cin >> h >> w >> d;
}
void putVolume()
{
cout << “Volume : “ << (h * w * d);
}
};
Class Definition, the internal details/implementation of ADT
25. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 25
Abstraction
Object : Box
State(Data)
Height
Width
Depth
Behaviour/Functions
getDimensions()
putVolume()
An Object of Class Box, user has knowledge about its external
interface only.
Actual implementation,
User has no knowledge
about this part of object.
External Interface to use
this object,
User has knowledge only
about this part of the object.
26. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 26
Encapsulation
The wrapping of code and data into a single unit is called
as encapsulation.
Encapsulation binds together data and code to
manipulate that data, it keeps both them safe from
outside interference and mis-use.
Encapsulation is a protective container that prevents code
and data from being accessed by other code defined
outside the container.
Creating a Class is the way to implement Encapsulation.
27. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 27
Encapsulation
Object encapsulates data and operations in one unit
An object is a bundle of data; who know how to do things
to itself.
28. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 28
Polymorphism
In object-oriented programming polymorphism means
the ability to appear in many forms.
polymorphism refers to a programming language's ability
to process objects differently depending on their data
type or class.
It is the provision of a single interface to entities of
different types.
29. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 29
Polymorphism
An operation may perform different behaviors in different
instances and the behavior depends upon the type of
data used in the operation.
30. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 30
Polymorphism
Consider the operation of adding two integer values using
+ operator, then the operation will generate a sum, but if
operands in the operation is of string type then the
operation would produce a third string by concatenation.
5 + 2 => 7 // integer operands
“Rising” + “Tech” => “Rising Tech” // string operands
31. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 31
Polymorphism
So this process of making an operator to perform
different behaviors in different instances is known as
“operator overloading”
32. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 32
Polymorphism
Class : Shape
---------------------------
Draw()
Object : Circle
---------------------
Draw(circle)
Object : Box
---------------------
Draw(box)
Object : Triangle
---------------------
Draw(triangle)
This figure illustrates that a single function name can be used to handle
different number and different type of arguments.
33. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 33
Polymorphism
Using a single function name to perform different types of
tasks is known as ‘Function Overloading’
This is something similar to a particular word having
several different meanings depending on the context.
I Saw a Saw with a Saw Sawing a Saw...
34. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 34
Virtual Functions
Virtual functions is the ability to redefine methods in
derived classes.
For example, given a base class shape, polymorphism
enables the programmer to define different area
methods for any number of derived classes, such as
circles, rectangles and triangles.
No matter what shape an object is, applying
the area method to it will return the correct results.
36. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 36
Polymorphism
Polymorphism plays an important role in allowing objects
to have different internal structures but to share the
same external interface.