- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 Data Hiding and Encapsulation
Data Hiding and Encapsulation are important concepts in object-oriented programming (OOP). Data hiding helps prevent the illegal or unauthorized access of members of a class, while encapsulation helps in the wrapping up of data members and methods inside a class. The most basic difference between data hiding and encapsulation is that data hiding focuses on data security, while encapsulation focuses on hiding the complexity of the system.
Read this article to find out more about Data Hiding and Encapsulation and how they are different from each other. Let's start with a basic overview of these two important concepts, Data Hiding and Encapsulation.
What is Data Hiding?
In object-oriented programming (OOP), data hiding is one of the important concepts that ensures the security of members of a class from illegal access. Therefore, data hiding protects the data members from being changed or hacked. As we know, data is the most sensitive and volatile content of a program, and the manipulation of this data can produce an incorrect result. Also, it may affects the integrity of the data.
Now, let us consider an example to understand the concept of data hiding. Let we declared a BankAccount class and we have a data member AcBalance inside this class. Here, the account balance is a sensitive information. In this example, we may allow an external application to check the account balance, but we would not allow the application to change the account balance. Hence, in this case, we restrict the alternation in account balance by declaring the account balance attribute private. The major advantage of data hiding is that it reduces the complexity of the system.
What is Encapsulation?
In object-oriented programming, Encapsulation is a method that helps wrapping up of data into a single module. Encapsulation brings together the data and the methods that manipulate the data into a single component and protects them from outside interference. Encapsulation mainly involves bundling the data as well as the functions that use the data.
Data encapsulation leads to the very important concept of data hiding. In short, encapsulation is a method of binding the data and functions together in a capsule to hide the complexity of a class. In encapsulation, the members inside a class can be public, protected, or private. The encapsulation is primarily used to make the system more user-friendly.
Difference between Data Hiding and Encapsulation
The following table highlights all the important differences between data hiding and encapsulation −
Data Hiding | Encapsulation |
---|---|
It is associated with data security. | It can be defined as the wrapping up of data into a single module. |
It also helps conceal the complexities of the application. | This will hide the complicated and confidential information about the application. |
It focuses on hiding/restricting the data usage. | It focuses on hiding the complexity of the system. |
It is considered as a process and a technique. | It is considered as a sub−process in the bigger process of data hiding. |
The data is always private and inaccessible. | The encapsulated data can be private or public, depending on the requirement. |
Conclusion
The most significant difference between these two concepts is that data hiding provides security unauthorized access of data, while encapsulation reduces the complexity of the system to make the application more user−friendly and fast.
- Related Articles
- Difference Between Abstraction and Data Hiding
- C++ program to hold student info using data hiding and encapsulation
- Difference Between Abstraction and Encapsulation
- Explain difference between Abstraction and Encapsulation in PHP.
- Difference between Method Overriding and Method Hiding in C#
- What is the difference between abstraction and encapsulation in Java?
- What is the difference between overriding and hiding in C#?
- What is the difference between method hiding and method overriding in Java?
- What is the difference between method overloading and method hiding in Java?
- What is the difference between function overriding and method hiding in C#?
- Data Hiding in Python
- Difference between data type and data structure
- Difference Between Data Warehouse and Data Mart
- Difference Between Data Mining and Data Warehousing
- Difference between Data Mining and Big Data
