Abstraction vs Encapsulation


Abstraction and Encapsulation are the two basic features of Object Oriented Programming.

  • Abstraction – Refers to the process of exposing only the relevant and essential data to the users without showing unnecessary information. It lets you focus on what the object does, instead of how it does it.
  • Encapsulation – Prevents the data from unwanted access by binding of code and data into a single unit.

 

                           Abstraction                             Encapsulation
Abstraction means to show only what is necessary. Encapsulation means to hide complexity.
Abstraction solves the problem in the design level. Encapsulation solves the problem in the implementation level.
Abstraction is implemented using interface and abstract class. Encapsulation is implemented using private and protected access modifier.
Abstraction is “To represent the essential feature without representing the back ground details.” Encapsulation means hiding the internal details of an object, i.e. how an object does something.
Abstraction provides you a generalized view of your classes or object by providing relevant information. Encapsulation means hiding details of implementation from outside world so that, when things change nobody gets affected. Encapsulation is also called data hiding.

 

4 thoughts on “Abstraction vs Encapsulation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s