OOP'S
OOP'S
Programming
Content
1) Problems in Procedure Oriented Programming
2) What is Object Oriented Programming?
3) What is an Object?
4) What is a Class?
5) Difference between Class and an Object
6) What is an Abstraction in Java?
a. How to achieve an Abstraction in Java?
b. Advantages of an Abstraction
7) What is an Encapsulation in Java?
a. How to achieve an Encapsulation in Java?
8) What is an Inheritance in Java?
9) What is a Polymorphism in Java?
No Reusability
The programmer concentrates on a specific task, and writes a set of functions to
achieve it
When there is another task to be added to the software, he would be writing another
set of functions
Thus, there will be no reusability of previous functions in most of the cases
Losing control on the code
Software developed following procedure oriented approach, naturally code size will
also be increased
When the code size exceeds 10,000 lines and before reaching 100,000 lines,
suddenly at a particular point, programmers were losing control on the code
Procedure oriented approach is unnatural
What is an Object?
1) An entity which does exist, has state and behavior is known as an object e.g. chair,
bike, marker, pen, table, car etc.
2) If something does not really exist, then it is not an object e.g. our thoughts,
imagination, plans, ideas etc.,
3) According to System existence means contains memory. So a software object
represents a memory.
4) Software objects also have a state and a behavior. A software object's state is stored
in variables and behavior is shown via methods. So an object contains variables and
methods
What is a Class?
1) It is possible that some objects may have similar properties and actions. Such
objects belong to same category called a ‘class’
2) It is only a logical component and not the physical entity e.g. if you had a class called
“Expensive Cars” it could have objects like Mercedes, BMW, Toyota, etc.
3) Its properties (data) can be price or speed of these cars.
4) While the methods may be performed with these cars are driving, reverse, braking
etc.
Relation between Class and Objects
Advantages of Abstraction
How to Achieve Abstraction in Java?
1) In Java, we can achieve Data Abstraction using Abstract class and Interface
2) Interface allows 100% abstraction (complete abstraction). Interface allow you to
abstract the implementation completely
3) Abstract class allow 0 to 100% abstraction (partial to complete abstraction) because
abstract class can contain concrete methods that have the implementation which
results in a partial abstraction
What is an Encapsulation?
1) We can define it as Encapsulation is the wrapping up of data and functions (methods
that operate on the data) into a single unit (called class).
2) There is a prohibition for direct access to the data. Functions (that combine with the
data) are the only way to access data. These functions are the member functions or
methods in Java. It basically creates a shield due to which the code or data cannot be
accessed outside the shield.
3) In Java class bind the data with its associated method so class is an example of
encapsulation