Abstraction
Abstraction allows us to represent the complex real world in the simplest manner. It is the process of identifying the relevant qualities and behaviors an object should possess, in other words representing the necessary feature without representing the background details. Abstraction is a process of hiding the work style of an object and showing only the information which are required to understand the object. Abstraction means putting all the variables and methods in a class that are necessary.
Encapsulation
It is a process of hiding all the internal details of an object from the outside real world. The word Encapsulation is like Enclosing into the capsule. It restricts the client from seeing its internal view where the behavior of the abstraction is implemented. In Encapsulation, generally to hides data making it private and exposes public property to access those data from the outer world. Encapsulation is a method for protecting data from unwanted access or alteration. Encapsulation is the mechanism by which Abstraction is implemented.
Difference between Abstraction and Encapsulation
Abstraction is a process. It is the act of identifying the relevant qualities and behaviors an object should possess. Encapsulation is the mechanism by which the abstraction is implemented.
Abstraction |
Encapsulation |
Abstraction solves the problem at the design level. |
Encapsulation solves the problem in the implementation level. |
Abstraction is used for hiding unwanted data and giving only relevant data. |
Encapsulation is hiding the code and data into a single unit to protect the data from the outer world. |
Abstraction is set to focus on the object instead of how it does it. |
Encapsulation means hiding the internal details or mechanics of how an object does something. |
Abstraction is the outer layout in terms of design. For Example: the outer Look of an iPhone, is like it has a display screen. |
Encapsulation is the inner layout in terms of implementation. For Example: - Inner Implementation detail of an iPhone, how Display Screen are connected with each other using circuits. |