Differences between Abstraction and Encapsulation
Differences between Abstraction and Encapsulation
Abstraction | Encapsulation |
1. Abstraction solves the problem at the design level. | 1. Encapsulation solves the problem in the implementation level. |
2. Abstraction hides unwanted data and provides relevant data. | 2. Encapsulation means hiding the code and data into a single unit to protect the data from the outside world. |
3. Abstraction lets you focus on what the object does instead of how it does it | 3. Encapsulation means hiding the internal details or mechanics of how an object does something. |
4. Abstraction: Outer layout, used in terms of design. For example: An external of a Mobile Phone, like it has a display screen and keypad buttons to dial a number. |
4. Encapsulation- Inner layout, used in terms of implementation.
For example: the internal details of a Mobile Phone, how the keypad button and display screen are connected with each other using circuits.
|
The easier way to understand abstraction and encapsulation is as follows.
Real-world Example
Use an example of a Mobile Phone
You have a Mobile Phone, you can dial a number using keypad buttons. You don't even know how these are working internally. This is called Abstraction. You only have the information that is necessary to dial a number. But not internal working of the mobile.
But how does the Mobile Phone work internally? How are the keypad buttons connected with internal circuit? That is called Encapsulation.
But how does the Mobile Phone work internally? How are the keypad buttons connected with internal circuit? That is called Encapsulation.
Comments
Post a Comment