ABSTRACTION AND ENCAPSULATION
ABSTRACTION
- Ignoring those aspects of an object that are
not relevant to the current scope of the
problem.
- Reduces scope and helps managing
complexity.
ABSTRACTION
- Designing a website to sell new Cars.
Car
Description
Type
Price
…
ABSTRACTION
- Do I need to include Service History as a
field? No (Because it does not belong to new
car and is not relevant to current scope)
- Do I need to include Vehicle Registration
Number as a field? No (Because currently we
do not have and it’s not necessary currently.
You get the number after you buy the car.)
ABSTRACTION
EXCLUDE WHICH IS
NOT RELEVANT TO THE CURRENT SCOPE
ENCAPSULATION
- Provides interface to access the functionality of
the object & hides how it is implemented.
- Keep the attributes and behavior as one unit
– Helps to make it more independent.
ENCAPSULATION
- Example of Pressing ’A’ on Keyboard.
Keyboard
Press A --- 65
1000001
Laptop
ENCAPSULATION
- Keys are exposed as interface and as an end
user when I press ‘A’, it is printed on the screen.
I do not know how it is implemented.
- Implementation is hidden as to how it displays
that on screen.
- Hiding implementation has a benefit – you can
change the implementation later but you can still
have the same interface. Maintenance is easy.
ENCAPSULATION
- Other aspect of attributes and behavior as one
unit is it helps to make the object independent.
- As a programmer, you know when you press
A, 65 (ASCII) is sent as signal but for end user it
does not matter.
- 65 is hidden from end user and it is private to
Keyboard object, only inner methods have
access to it. This keeps them as one unit and
encapsulated.
CONCLUSION
- Abstraction comes before Encapsulation
- In Abstraction, we are trying to come up with
the scope of the problem.
- In Encapsulation, we are trying to come up
with the approach to solve and implement
problem in a better way.

Abstraction and Encapsulation

  • 1.
  • 2.
    ABSTRACTION - Ignoring thoseaspects of an object that are not relevant to the current scope of the problem. - Reduces scope and helps managing complexity.
  • 3.
    ABSTRACTION - Designing awebsite to sell new Cars. Car Description Type Price …
  • 4.
    ABSTRACTION - Do Ineed to include Service History as a field? No (Because it does not belong to new car and is not relevant to current scope) - Do I need to include Vehicle Registration Number as a field? No (Because currently we do not have and it’s not necessary currently. You get the number after you buy the car.)
  • 5.
    ABSTRACTION EXCLUDE WHICH IS NOTRELEVANT TO THE CURRENT SCOPE
  • 6.
    ENCAPSULATION - Provides interfaceto access the functionality of the object & hides how it is implemented. - Keep the attributes and behavior as one unit – Helps to make it more independent.
  • 7.
    ENCAPSULATION - Example ofPressing ’A’ on Keyboard. Keyboard Press A --- 65 1000001 Laptop
  • 8.
    ENCAPSULATION - Keys areexposed as interface and as an end user when I press ‘A’, it is printed on the screen. I do not know how it is implemented. - Implementation is hidden as to how it displays that on screen. - Hiding implementation has a benefit – you can change the implementation later but you can still have the same interface. Maintenance is easy.
  • 9.
    ENCAPSULATION - Other aspectof attributes and behavior as one unit is it helps to make the object independent. - As a programmer, you know when you press A, 65 (ASCII) is sent as signal but for end user it does not matter. - 65 is hidden from end user and it is private to Keyboard object, only inner methods have access to it. This keeps them as one unit and encapsulated.
  • 10.
    CONCLUSION - Abstraction comesbefore Encapsulation - In Abstraction, we are trying to come up with the scope of the problem. - In Encapsulation, we are trying to come up with the approach to solve and implement problem in a better way.