- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
- Related Articles
- Explain difference between Abstraction and Encapsulation in PHP.
- What is the difference between abstraction and encapsulation in Java?
- Abstraction vs Encapsulation in Java
- Difference between Abstraction and Virtualization
- Difference between encapsulation and decapsulation
- Difference Between Abstraction and Data Hiding
- Difference Between Data Hiding and Encapsulation
- Abstraction in Java
- Abstraction in C++
- PHP Class Abstraction
- Encapsulation in Java
- Encapsulation in C#
- Encapsulation in C++
- What is abstraction in C#?
- Explain Encapsulation in PHP.
