Difference Between Abstraction and Encapsulation


Abstraction is a process of hiding the implementation details of a system from the user, and only the functional details will be available to the user end. On the other hand, Encapsulation is a method of wrapping up the data and code acting on the data into a single unit.

Read this article to find out more about abstraction and encapsulation and how they are different from each other.

What is Abstraction?

Abstraction is defined as a process of hiding the implementation details of a system from the user. Thus, by using abstraction, we provided only the functionality of the system to the user. Consequently, the user will have information on what the system does, but not on how the system does it.

For example, when we consider the case of a search on google, complex details such as what happens as soon as we search about a query, the protocol our web server uses are hidden. Therefore, to make a search on google we just need to type the query, and click on the search button.

What is Encapsulation?

Encapsulation is one of the fundamental OOP concepts. Encapsulation is defined as a method by which data wrapping is done into a single unit. It is used in wrapping up the data and the code acting on the data together as a single unit.

In encapsulation, the variables of a class are hidden from other classes, and can be accessed only by methods of the current class. Therefore, encapsulation is also called data hiding. Encapsulation is implemented using access modifiers like public, private and protected.

Difference between Abstraction and Encapsulation

The following table highlights all the important differences between abstraction and encapsulation −

S.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.

Conclusion

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.

Updated on: 13-Sep-2023

32K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements