Abstraction is a process of
collecting crucial information that will make a base for building a
complex system. Encapsulation is a process of developing a complex system much
easier to manage end user, without worrying about its inner complexities. The
difference between abstraction and encapsulation is that
abstraction focuses on identifying the essential components for building a
system while encapsulation focuses on hiding the inner complexities of a system.
Elements that are required to develop a
|Encapsulation is a process of developing a complex system|
|Achievement||Achieved through encapsulation.||
Achieved through making the members of a
class as private.
|Focuses||Focus is on what should be done||Focus is on how it should be done.|
|Application||During design level.||
During the Implementation
The GUI of a cell phone, it has some icons to click, which on
click perform the specific function.
When icon is clicked,
the end user has no idea regarding its implementation details
What is Abstraction?
Abstraction is a mechanism of extracting the crucial elements
for the creation of a system, without its implementation details. In
abstraction, we must concentrate only on what is to be done rather than how it
needs to be done. Abstraction is a thought process, it solves the problems at the design
Hierarchical classification helps us to handle a complex abstraction. It enables us to break a complicated system into manageable pieces and generate a layered semantics. Furthermore, it is a generalization.
Let us take a good example of a Car, it is created from a number of subsystems like engine, brakes, lighting, audio system, chair and a much more. The ‘brake’ that is a subsystem of a bicycle can further be categorized as front wheel brake and rear wheel brake, but generally, we see all subsystem as brakes. So, we must manage the complex system by hierarchical classification, which helps us to find out what are the crucial elements that will be required to develop a system.
So, abstraction is only generalizing what elements are
essential for making a system, i.e. picking up the important ones just.
What is Encapsulation?
Encapsulation is the important feature of object-oriented programming. It’s a mechanism that
binds code and data together and keeps them protected from the external
interference. That is to say, encapsulation hides the complexity of a system,
since the keyword here is data hiding. It’s similar to a protective
wrapper that hides the code and data within the class, being obtained by
another code that’s defined outside the class and the member function/method
that are not the members of the class.
When code and data that operate
on that data, are linked in class, then the objects of this class are created.
The access to the elements of the item is limited by a well-defined interface
known as access specifier. There are three access
specifiers in Java and C++ Public, Private, Secure.
The encapsulation is especially achieved by making the code
and data that operates on the data, as private. The private members of the class cannot access from the code defined
outside the class. It assists in preventing the misuse of data whereas it also hide complexity
of the code.
Let us take an example of a cell phone. In a cell phone, you
can perform many functions like clicking a picture, recording a video/audio,
sending a message, access the web and much more. You consider these as the
characteristics of a cell phone. But, the final user does not need to
understand the internal complexity of those features, prior to using these
programs, nor you need to alter the functionality of any of the function.
So, this manner, the encapsulation hides the complexity and
prevent the misuse of the data.
Key Differences between Abstraction and Encapsulation
- Abstraction focuses on components that are required to
construct a system while encapsulation focuses on hiding the complexity of the
- The abstraction is done during the design level of a system and
encapsulation is done when the system has
- Abstractions main motive is, what’s to be done in order to build
a system while Encapsulations main motive is, how it should to be done to construct a system.
- Abstraction is achieved by
encapsulation whereas, the encapsulation is achieved by making the elements of
the system private.
Abstraction and encapsulation
both are be the important feature of OOP. A great encapsulation can achive a fantastic abstraction.