Page 1 of 2
Difference Between Abstraction and Encapsulation
Differences Data Visualization Web Services
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 ?
Page 2 of 2
S.No Abstraction Encapsulation
It is the process of gaining It is a method that helps wrap up data
1.
information. into a single module.
The problems in this technique are Problems in encapsulation are solved
2.
solved at the interface level. at the implementation level.
It helps hide data using a single entity,
It helps hide the unwanted
3. or using a unit with the help of method
details/information.
that helps protect the information.
It can be implemented using access
It can be implemented using
4. modifiers like public, private and
abstract classes and interfaces.
protected.
The complexities of the
The data is hidden using methods such
5. implementation are hidden using
as getters and setters.
interface and abstract class.
Abstraction can be performed using
Objects in encapsulation don't need to
6. objects that are encapsulated within
be in abstraction.
a single module.
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.