Abstraction and Data hiding are the crucial concepts of object-oriented programming. Abstraction is a method of expressing important properties without involving background details. On the other hand, Data hiding isolates data from direct access from the program. Although, both concepts sound similar in the sense, but they are different. Abstraction provides a way to create user-defined data types to design real world objects having the same properties. As for data protection, it protects data and function from unauthorized access.
|Basic||It only extracts the relevant information and ignores the nonessential details.||Hides data from parts of the program.|
|Purpose||To hide the complexity.||To achieve encapsulation.|
|Class||Class uses abstraction to derive a new user-defined data type.||Data hiding is used in a class to make its data private.|
|It focuses||Observable data behavior.||Restrict or allow the use of data within a capsule.|
Definition of abstraction
abstraction it is mainly used to hide complexity. Indicates the necessary characteristics of an object that differentiates it from all other types of objects. An abstraction focuses on the external appearance of an object. For an object, abstraction provides the separation of crucial behavior from its implementation. Specifies a conceptual limit relative to the viewer's perspective. An appropriate abstraction emphasizes the details that are important to the reader or user and suppresses the features that are irrelevant and deviant.
User-defined data types are created by defining abstract attributes and functions within a class to design real-world objects with similar properties. These attributes are known as data members because they contain information. Likewise, the functions that operate on this data are known as member functions. Data abstraction implemented as a class that represents essential properties without including background explanations.
Types of abstraction:
- Procedural abstraction – Includes series of instructions with the specified functions.
- Data abstraction : a dataset that specifies and describes a data object.
- Control of abstraction – a program control mechanism where internal details are not specified.
Definition of hiding data
Concealment of data involves hiding data from program components that you don't need to recover. The isolation of data from direct access by the program called hide data or hide information. For the implementation of data hiding, encapsulation is used when the data and functions of a class are protected from unauthorized access. On the contrary, when the data and the function are enclosed in a single unit known as encapsulation. Hence, data hiding helps to achieve encapsulation. Functional details of an object can be managed through access specifiers.
Using the concepts that hide data, the data and functions of a class are made private so that they cannot be accessed incorrectly by functions outside the class and protected from accidental alterations.
Key differences between abstraction and data hiding
- The abstraction shows the relevant information and rejects nonessential details. On the other hand, data hiding is used to hide data from parts of the program.
- The previous purpose of abstraction is to hide the complex implementation details of the program or software. On the contrary, data hiding is implemented to achieve encapsulation.
- Abstraction is used in the classroom to create a new user-defined data type. By contrast, the concealment of data is hidden in the classes to make the data private.
- Abstraction focuses on observable data behavior while hiding data limits or allows the use of data within a capsule.
Both abstraction and data hiding were meant only to show the required information and to hide the details of the essentials, but for the distinct purpose. The abstraction emphasizes hiding the complexity of implementation while in data that hides the importance given to protecting data against unauthorized access.