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.” tutorialspoint.com, Tutorials Point, 24 Mar. 2018, .
2.“Abstraction in Java.” GeeksforGeeks, 14 Nov. 2017, .
3.“Encapsulation in Java.” Javatpoint, .

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


Related pages


difference between cystitis and bladder infectiondifference resistance and resistivityamidst in a sentencegametophyte generation definitionprinciple of linear momentumfull costing absorption costingexamples of indefinite pronoundifference between edt and estdisgust nounangle of twist definitionthe difference between gerund and infinitivecentripetal vs centrifugal forcesdark matter and antimatterc pap vs bi papwhat is the difference between macro and micronutrientsmuffin vs cupcakesdefine elocutionistfeatures of cold blooded animalspsychoanalytic criticism theoryautism and spd3d vector addition calculatormoral lesson of the ant and the grasshopperexample of literal and figurativedifference between ldpe and hdpecovalent ionic and metallic bondingwhat is the difference between a hispanic and latinodrank in a sentencesashimi sushi differenceexamples of activity based costingalright vs all right grammarmonerans and protistsdifference between a bucket and a paildifference between cities and villagesmolecular formula cyclohexanebull vs english mastiffdifference between direct object and indirect objectgold foil experiment explanationwhat is sexual and asexualhow to calculate least count of micrometer screw gaugeleukopenia neutropeniafondant royal icingcollective noun of chairsdifference between caster sugar and raw sugardifference between spinal block and epiduralamerican bull pitbullxanthan gum guar gumdifference between paraphrase and summarymitosis processwhich animals are cold bloodedwhat does atp and adp stand fordifference between enzymes and hormoneseminent in a sentencethe difference between mitosis and cytokinesisdifference between msc and mphilexamples for eubacteriatwo centrosomes are arranged at opposite poles of the cellchemical formula for nitrateembryo and foetusexample of proper and common noundescribe the differences between spermatogenesis and oogenesiswhat does sardonicwhat is the difference between flat white and lattesichuan kung pao chickendifference between mosfet and jfetcapitol capital differencepixie folklorematron vs maid of honorschizophrenia or schizoaffective disordervulcanized rubber structureneoclassicism literatureexamples of transnational corporationsdefine tardive dyskinesiaprotostomes deuterostomesdefinition of bistroexamples of monocot and dicot flowers