link: OOP, Abstraction, Encapsulation
Abstraction vs Encapsulation
Lets take a look on difference between Abstraction vs Encapsulation
A lot of times programmers often confuse abstraction with encapsulation because in reality the two concepts are quite intertwined and share a relationship between them. Abstraction, as we’ve seen pertains to hiding underlying details and implementation in a program. Encapsulation, on the other hand, describes how abstraction occurs in a program.
Abstraction is a design-level process but encapsulation is an implementation process. Encapsulation tells us how exactly you can implement abstraction in the program. Abstraction pertains to only displaying the essential details to the user whereas encapsulation pertains to typing up all the data members and associated member functions into a single abstracted unit.
No | Abstraction | Encapsulation |
---|---|---|
1. | It is the process of gaining information. | It is a method that helps wrap up data into a single module. |
2. | The problems in this technique are solved at the interface level. | Problems in encapsulation are solved at the implementation level. |
3. | It helps hide the unwanted details/information. | It helps hide data using a single entity, or using a unit with the help of method that helps protect the information. |
4. | It can be implemented using abstract classes and interfaces. | It can be implemented using access modifiers like public, private and protected. |
5. | The complexities of the implementation are hidden using interface and abstract class. | The data is hidden using methods such as getters and setters. |
6. | Abstraction can be performed using objects that are encapsulated within a single module. | Objects in encapsulation don’t need to be in abstraction. |
Important
The most significant difference between the two is that data abstraction is a method which helps to hide the unwanted data from the user, while data encapsulation is a method which helps to hide data using a single entity.
References
Abstraction vs Encapsulation - Google