Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference in Information hiding and data abstraction?

Is there any difference in Data Abstraction and Information hiding? After going through all the answers in this link I am more confused. Abstraction VS Information Hiding VS Encapsulation Couldn't find any difference. Is it just that we can call one (info hiding) as a goal & the other (abstraction) as a process? But this is no satisfactory difference for me. Further, I got that encapsulation is the technique to implement the process of abstraction Am I right here? Please explain the exact difference.

like image 338
Ankita_K Avatar asked Aug 29 '11 18:08

Ankita_K


1 Answers

Information hiding is when the designer specifically decides to limit access to details of an implementation. It's a principle that's older than object-oriented design, but is often used.

A simple example is defining constants in C, e.g., #define NAME_SIZE 15 The code (clients) of the constant don't need to know its value, and won't be troubled if you (the designer) decide to change its value later. They shouldn't make assumptions about the fact that it's really 15, because you might decide to change it.

Abstraction is when you're dealing with an aggregate, e.g., a Car is an abstraction of details such as a Chassis, Motor, Wheels, etc. Abstractions allow us to think of complex things in a simpler way.

Encapsulation is how we decide the level of detail of the elements comprising our abstractions. Good encapsulation applies information hiding, to enforce limits of details. For example, my Car is comprised in reality of all its parts, yet it only provides to me (the driver) an interface that's appropriate for my needs and not more. I can control the doors, locks, windows, lights, horn, sunroof, the direction of the movement, accelerate, decelerate, etc. Even though I might be curious to manipulate the details of the "how" of all these things, encapsulation prevents me from seeing more.

If my car's implementation changes (I change from a combustion engine to an electric or hybrid), because I as the driver know only the limited interface, I don't need to change how I drive the car. Abstraction allows me to just know I'm driving a car, instead of hundreds of pieces of metal, rubber, etc.

An example of where information hiding was not part of a car might be a choke valve. My parents told me how those used to work in the cars they drove... it was a combustion-engine detail, which would not be useful in an electric car.

like image 153
Fuhrmanator Avatar answered Nov 27 '22 12:11

Fuhrmanator