Difference Between Data Abstraction and Encapsulation

The main difference between Data Abstraction and Encapsulation is that the data abstraction hides the implementation details and shows only the functionality to the user in order to reduce the code complexity while the encapsulation binds or wraps the data and methods together into a single unit and hides the details for data protection.

Object Oriented Programming (OOP) helps to model the real world scenarios into software. It is a paradigm or a methodology to design a program using classes and objects. A class is a blueprint to create an object. In other words, it is a structure to create objects. It consists of attributes and methods. The attributes describe the properties or data while the methods describe the operations or behaviors. It is not possible to create objects without classes. Therefore, an object is an instance of a class. Data Abstraction and Encapsulation are two concepts in OOP.  

Key Areas Covered

1. What is Data Abstraction
     – Definition, Usage
2. What is Encapsulation
     – Definition, Usage
3. Difference Between Data Abstraction and Encapsulation
     – Comparison of Key Differences

Key Terms

Data Abstraction, Encapsulation, OOP

Difference Between Data Abstraction and Encapsulation - Comparison Summary

What is Data Abstraction

Data Abstraction refers to hiding the internal details and just showing the functionality.  In other words, it hides the implementation details and just present the features to the outside world. One real-world example is a television. The user does not need to know the internal electronic circuits and the functionalities to watch television. Another example is using a mobile phone. The user does not need to know internal processing. He just needs to know the main functionalities such as making phone calls, sending messages or browsing the internet.

Data Abstraction provides advantages in software development. Most importantly, it reduces code complexity. Furthermore, it hides details and exposes the essential features. The OOP supporting languages help to achieve data abstraction using abstract classes and interfaces.

What is Encapsulation

Encapsulation combines data and methods into a single unit. The main objective of encapsulation is to secure the data.  It is similar to a medical capsule. Medicine is inside the capsule and it is covered and protected from the outside world.

Difference Between Data Abstraction and Encapsulation

Figure 01: Encapsulation

The method to achieve encapsulation is by using access modifies such as “private” and “public”. They change the visibility of the data or the methods. The private members are only accessible within the class while the public members are accessible within the class and by other classes.

It is possible to implement encapsulation in OOP language by making the data members or properties private and accessing them through public methods such as getters and setters. Likewise, Encapsulation compact the data and method to one unit. Moreover, it provides protection for the data.

Difference Between Data Abstraction and Encapsulation

Definition

Data Abstraction is an OOP concept that hides the implementation details and shows only the functionality to the user. Encapsulation is an OOP concept that binds or wraps the data and methods together into a single unit.

Main Usage

Data Abstraction hides the implementation details to reduce the code complexity while encapsulation hides data for the purpose of data protection. This is the main difference between data abstraction and encapsulation with regards to the usage of the two. 

Method of Achieving

OOP languages use abstract classes and interfaces to achieve Data Abstraction. In contrast, OOP languages can achieve Encapsulation by making the data members private and accessing them through public methods.

Conclusion

Data abstraction and encapsulation are two concepts in OOP (Object Oriented Programming). The difference between data abstraction and encapsulation is that the data abstraction hides implementation details to reduce code complexity while the encapsulation hides details for data protection.

Reference:

1.Tutorials Point. “Java Encapsulation.” Www.tutorialspoint.com, Tutorials Point, 24 Mar. 2018, Available here.
2.“Abstraction in Java.” GeeksforGeeks, 14 Nov. 2017, Available here.
3.“Encapsulation in Java.” Javatpoint, Available here.

About the Author: Lithmee

Lithmee holds a Bachelor of Science degree in Computer Systems Engineering and is reading for her Master’s degree in Computer Science. She is passionate about sharing her knowldge in the areas of programming, data science, and computer systems.

Leave a Reply