Earlier we discussed about
basics of Object oriented programming ,
what abstraction in OOPs is and
what encapsulation means . Today let us see what differentiates abstraction from encapsulation.
- Abstraction is implemented through Interface and abstract classes in Java. While encapsulation is implemented by using access modifiers like private, public and protected.
- Encapsulation is also called data hiding. That is hiding the details from outside the world.
- Abstraction is based on design principal of “programming for interface than implementation” and basis of encapsulation is “encapsulate whatever changes”.
- Abstraction resolves the problem at the design level but the encapsulation resolves the problem at the implementation level.
- Abstraction hides the irrelevant details and gives relevant information. Encapsulation is encapsulating data and functions into single unit so that it can be protected from outside the world.
- Abstraction focuses on what the object does rather than how it does. Encapsulation hides the internal features which implement the functionality of the class.
- Example of abstraction is “Outer look of the mobile like the display screen on which the numbers are displays and keypads on which the digits and other character are displayed”. Example of encapsulation is inner layout of the mobile phone like how the how the keypad and its different buttons are connected with the screen.
|
Difference between Abstraction and Encapsulation |
Copyright © ianswer4u.com
0 Reactions:
Post a Comment