Abstraction vs Encapsulation
Abstraction is a basic OOP concept which focuses on just the relevant data of an object and hides all the irrelevant details which may or may not be for generic or specialized behavior. It hides the background details and emphasizes on the essential points to reduce complexity and increase efficiency. Basically, abstraction is a programming tool to manage complexity. Abstraction focuses on ideas rather than events. It hides the details on the design level by providing functionality to the users. The resulting object can also be called an abstraction. The programmer makes sure the named entity will have all the essential aspects included and none of the irrelevant ones.
Encapsulation is yet another OOP concept which binds data and functions into a single component while restricting access to some components. It’s one of the main fundamental concepts of OOP which wraps data and information under a single unit. In technical terms, encapsulation means hiding attributes to shield variables from outside access so that change in one part of an application won’t affect the other parts. On the contrary, by making the information more open you’ll risk misuse of data. It provides basic integrity to the data by protecting it from the outside world. In simple terms, it hides the extra details from the outside world.
Abstraction | Encapsulation |
---|---|
Is the process or method of gaining the information | Is the process or method to contain the information |
Problems are solved at the design or interface level | Problems are solved at the implementation level |
Is the method of hiding the unwanted information | Is a method to hide the data in a single entity or unit along with a method to protect information from outside |
Can be implemented by using abstract class and interfaces | Can be implemented using by access modifier i.e. private, protected and public |
Implementation complexities are hidden using abstract classes and interfaces | The data is hidden using methods of getters and setters |
The objects that help to perform abstraction are encapsulated | Whereas the objects that result in encapsulation need not be abstracted |
Links
https://www.geeksforgeeks.org/difference-between-abstraction-and-encapsulation-in-java-with-examples/
http://www.differencebetween.net/technology/difference-between-abstraction-and-encapsulation/