The main difference between data hiding and abstraction is that data hiding helps to secure data while abstraction helps to hide the complexity of the system.
Object-Oriented Programming (OOP) is a paradigm that helps to create solutions to the real world scenarios easily than using other paradigms such as structured programming. OOP is based on designing the program using classes and objects. A class is a plan or a blueprint to create objects. It contains attributes and methods. Attributes are the data members that describe the properties of the object. Methods describe the behaviors. Objects are created using classes. Data hiding and Data abstraction are two important concepts in OOP.
Key Areas Covered
1. What is Data Hiding
– Definition, Functionality
2. What is Abstraction
– Definition, Functionality
3. What is the Difference Between Data Hiding and Abstraction
– Comparison of key differences
Abstraction, Class, Data Hiding, Objects, OOP
What is Data Hiding
A class consists of data members and methods. Data hiding helps to protect the members of a class. Programming languages such as Java have access modifiers like public, private and protected. Objects of other classes can access public data members and methods. However, protected members are accessible by the objects of the same class and its subclasses. Moreover, private members are only accessible within the class. Therefore, these access modifiers help to secure the members.
When it is necessary to restrict objects of other classes from accessing the members of a class, the programmer can use the private access modifier. Then, the data members are only accessible within the class. It is also possible to make the data members private and allow accessing them through public methods (getters and setters).
Encapsulation is a major concept in OOP. It wraps the data members and methods into a single unit. Furthermore, it is a way of achieving data hiding. Overall, data hiding helps to protect the members of the class.
What is Abstraction
Abstraction hides the internal details and displays only the functionality to the users. In other words, it hides the implementation details and presents the functionality to the outside world. For example, assume a real-world application such as a mobile phone. The user does not need to understand the internal structure, circuitry of the mobile phone to take calls, send SMS, and play games or to browse the internet.
In OOP supporting programming languages such as Java, it is possible to implement abstraction using abstract classes and interfaces. An abstract class can have abstract and non-abstract methods. A class that extends an abstract class should provide the definitions for the abstract methods. Furthermore, all the methods in an interface are abstract methods. Therefore, a class that implements an interface should provide the definitions for all those abstract methods.
Difference Between Data Hiding and Abstraction
Data hiding is the process that ensures exclusive data access to class members and provides object integrity by preventing unintended or intended changes. Abstraction, on the other hand, is an OOP concept that hides the implementation details and shows only the functionality to the user. Thus, this is the main difference between data hiding and abstraction.
While data hiding focuses on protecting data, abstraction focuses on hiding the complexity of the system. Hence, this is another difference between data hiding and abstraction.
Moreover, one other difference between data hiding and abstraction is that the data hiding helps to secure the data while abstraction helps to hide the implementation details and display only the functionalities to the user.
Data hiding and abstraction are two concepts related to OOP. Data hiding secure the data members. Encapsulation is used to achieve data hiding. On the other hand, abstraction helps to reduce the complexity of the system. It also limits access to the internal details and shows the essential features of the software to the user. The main difference between Data Hiding and Abstraction is that Data hiding helps to secure data while Abstraction helps to hide the complexity of the system.
1. “CPT-OOP-objects and classes” By Pluke – Own work, (CC0) via Commons Wikimedia