15CSE202 Object Oriented Programming
15CSE202 Object Oriented Programming
Nalinadevi Kadiresan
CSE Dept.
Amrita School of Engg.
15CSE202 Object oriented Programming 2
Roadmap
Abstraction
Encapsulation
Inheritance
Modularity
Strong Typing
Concurrency
Persistence
Abstraction - Modelling
pop(); delete();
gallop(); fly();
canter(); hunt();
gallop(); fly();
canter(); }; hunt(); };
Behaviour
member functions
methods
June 2019 Nalinadevi Kadiresan
15CSE202 Object oriented Programming 10
Objects
An object has state, exhibits some well defined behaviour, and has a unique identity.
Class
Roadmap
Abstraction
Encapsulation
Inheritance
Modularity
Strong Typing
Concurrency
Persistence
int read_x()
{
return x;
}
Encapsulation
FIRST LAW OF OOP: Data must be hidden,
i.e.,PRIVATE
Read access through read functions
Write access through write functions
For every piece of data, 4 possibilities
>>read and write allowed
>>read only
>>write only
>>no access
June 2019 Nalinadevi Kadiresan
15CSE202 Object oriented Programming 24
Encapsulation
Encapsulation hides the details
of the implementation of an
object.
Initialization of Objects
Resource Deallocation
Special Functions – DESTRUCTORS
ensure correct initialization of all
resources before an object “dies”
(goes out of scope).
Lifecycle of an Object
Born healthy
using constructors
Lives Safely
using read/write functions
Dies cleanly
using destructors
Lifecycle of an Object
Born healthy
using constructors BRAHMA
Lives Safely
using read/write functions VISHNU
Dies cleanly
using destructors MAHESHWARA
Anatomy of a Class
PRIVATE PUBLIC
Constructors
Destructors
Roadmap
Abstraction
Encapsulation
Inheritance
Modularity
Strong Typing
Concurrency
Persistence
Stack 1
June 2019 Nalinadevi Kadiresan
15CSE202 Object oriented Programming 36
Subclasses - Inheritance
Inheritance
Inheritance Trees
Animal
Vertebrates Invertebrates
is-a
relationship
Gorillas Chimpanzees Humans
Inheritance Trees
Employee
is-a
relationship
Manager
Nomenclature
BEST
Not recommended
Multiple Inheritance
Horse Eagle
Flying
Horse
H
June 2019 Nalinadevi Kadiresan
15CSE202 Object oriented Programming 44
Inheritance Trees
Animal
Vertebrates Invertebrates
Horse
Eagle
eat()
eat()
Flying Horse
eat()?
Overridding
• Redefining a
inherited method
Polymorphism
Roadmap
Abstraction
Encapsulation
Inheritance
Modularity
Strong Typing
Concurrency
Persistence
Modularity
Modularity packages abstractions into discrete
units.
Classes
Packages
Domains
Roadmap
Abstraction
Encapsulation
Inheritance
Modularity
Strong Typing
Concurrency
Persistence
Strong Typing
Strong typing prevents mixing abstractions.
X=Y
Roadmap
Abstraction
Encapsulation
Inheritance
Modularity
Strong Typing
Concurrency
Persistence
Concurrency
Concurrency allows different objects to act at the
same time.
Roadmap
Abstraction
Encapsulation
Inheritance
Modularity
Strong Typing
Concurrency
Persistence
Persistence
Persistence saves the state and class of an object
across time and space, i.e., storage on permanent
storage media.
Recap
Abstraction
Encapsulation
Inheritance
Modularity
Strong Typing
Concurrency
Persistence
Picture courtesy