Difference between Abstraction and Encapsulation

Key difference: Abstraction and Encapsulation are computer-science programming concepts. An abstraction is a process, in which the extra characteristics of the data are removed or separated from the data; whereas, an encapsulation is a mechanism, in which the data is hidden and bundled in methods.

Abstraction is a generalized process in which the extra data is taken away and removed in order to make the data concrete. In computers, it’s a programming method which helps in converting the data to a concise form. The data and program are not changed in this method, rather they are kept in the same initial form; the only difference is that they are reduced to a smaller presentable form. Abstraction tries to reduce and factor out the details, so that the programmer can focus on a few concepts at a time.

A system can have many such layers of abstractions, which have different meanings and details. For example, low-level abstraction layers expose details of the computer hardware where the program runs, while high-level layers deal with the business logic of the program. These details are then exposed to the programmer at the time of execution. Abstraction is a concept or an idea, which is not associated to any particular instance. It captures only those details of the data which are concerned with its objects and current perspectives. It plays a major role in the family of objects (in the concepts of Object-Oriented-Programming). and is used in different ways and implementations.

The concept of abstraction can be implemented in:

  • Control Abstraction: It is the abstraction of actions.
  • Data Abstraction: It allows and handles the data bits and data structures in meaningful ways.

Encapsulation in computer programming highlights its functions into two different notations, they are as:

  • A language mechanism which restricts the access to some object's components.
  • A language construct that facilitates the bundling of data with the methods (and other functions) operating on that data.

Encapsulation is the hiding mechanisms, which plays a vital role in protecting and securing the data from the outsiders. It actually provides the basic integrity to the data by preventing the misuse of real data. In encapsulation, the data is stored and accessed in its original valid and consistent format.

In general, encapsulation means preserving an object from the user and representing it in a general form. Basically, in encapsulation the extra details are hidden from the outside environment. The objects fields are directly inspected and manipulated in this mechanism. The information hiding along with the furnishing are compiled in a version, which is further used as the source code and is interfaced via a header file. Sometimes, the public classes try to access the data, at these instances the encapsulation does not allow the public invaders to play with the data. One of the major benefits of encapsulation is that, it helps in the reduction of the complexity of a program, and helps the users to understand the exact concepts of the program, as the mechanisms represents only the concise form of the program. This increases the robustness, by allowing the developer or programmer to limit the inter-dependencies between software components. Encapsulation is also applicable in some languages like, Smalltalk and Ruby, in which the accessing is allowed only via object methods; while most others like, C++, C# or Java offers a degree of control to the programmer. These languages allow the developers to access over what is hidden with the help of keywords like public and private.

The Abstraction and Encapsulation are also major fundamentals in the OOP (Object-Oriented-Programming).

Comparison between Abstraction and Encapsulation:

 

Abstraction

Encapsulation

Short description

Abstraction is a process, which extracts the essential details about an item, or group of items, and ignores the inessential details.

Encapsulation is a process which wraps or encloses the data in a capsule or makes the data concise.

They are

Abstraction relates to the idea of hiding data that is not needed for presentation.

Encapsulation is grouping together of data and functionality.

Basic functions

Basically, abstraction is used for hiding the unwanted data and it gives the relevant data.

Basically, encapsulation means hiding the code and data into a single unit in order to protect the data from the outside world.

When are they Operated

It operates the problem in the design level.

It operates the problem in the implementation level.

Beneficial to the roles

It helps the user to focus on what the object does instead of how it does any function.

It helps the programmer in hiding the internal details or mechanics of how an object does something.

Information is

Here information is separated from the real data.

Here information is wrapped in a hidden format.

Layouts

It is concerned with the outer layout, which is used in terms of design.

It is concerned with the inner layout, which is used in terms of implementation.

For Example

The Outer Look of a Mobile Phone, which has a display screen and keypad buttons to dial a number.

Inner Implementation detail of a Mobile Phone, how the keypad button and Display Screen are connected with each other using circuits.

Image Courtesy: java9s.com, placementyogi.com

Most Searched in Food and Drink Most Searched in Sports
Top 10 Most Searched Differences Most Searched in Home and Garden
Noir vs Neo-Noir
All The Best vs Best Of Luck
Law vs Ethics
Jealousy vs Envy

Comments

Thanks this is useful notes! i copy this for my presentation ! huhu

Add new comment

Plain text

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.