Please tell me the difference between these three. I know the basic meaning but don't know exact meaning of all of them. Please explain a very good example if possible. Thanks in advance.

2 Years
Discussion Span
Last Post by rubberman

What is the basic meanings of them?

Votes + Comments
I think that Suzie is trying to get the poster to think about what these terms mean for them.

Warning: Software engineers love to provide vague definitions for every term, and then, they vehemently insist that they are very different and should not be confused for one another.

Basically, information hiding and encapsulation are, in a way, two sides of the same coin. The idea of information hiding is that your users should not know more about your code (classes, functions, etc.) than they need to to be able to use it. The idea of encapsulation is that your code shouldn't be spilling its guts in public, i.e., it should be neatly packed and hermetically sealed. Clearly, that sounds like the same thing, and it often is in practice (there are many ways, especially in C++, to implement both, and they are often the same). The critical difference is in the point of view, not so much in the actual code. They are two ideals. Information hiding is the ideal of minimizing (down to the essentials) the information about your implementation that the user is exposed to. Encapsulation is the ideal of minimizing the dependencies to external components (or other components of your library) down to only what is essential to its use. In other words, let's say you are writing component A and to write it you use component B, but the user does not need to know about that when using component A, well, information hiding tells you that he shouldn't know that A uses B, and encapsulation tells you that he shouldn't be bothered by A's dependence on B.

Abstraction is a very different concept and is fairly well presented in its wiki page. Abstractions in C++ typically materialize in the form of (abstract) base-classes and generic concepts, but come in many other forms too.


You ask to differecetiate b/w data hiding ,ecapsulation and adstraction.
Data hiding:it means hide your data from the user by using set() and get() fuctions and your user never know about the private members of your class.

Encapsulation: it means data and behaviors(functions) are combined inside an object.As you know object of class change its states and it also has some behaviors so you can say that encapsulation is the tightly coypling of states and behaviors.

Abstraction: it neans abstract the only necessary details in the system that are required to make a funcional system (by using programing )


The use of abstraction is that you can create an abstract base class with all the functions you need for derived concrete classes of that type, so that you only need a pointer or reference to the base class in order to do useful stuff. I used these extensively in a framework I wrote years ago to model what we called "storage adapters". We had concrete classes derived from the StorageAdapter class for storing data over the network (BusStorageAdapter) or directly to a database (DatabaseStorageAdapter). The application developer only needed to tell the object to store itself - each class knew what storage adapter they were to use. The developer didn't need to know that the actual storage was local or remote. It would do the right thing in either case. If the class used a BusStorageAdapter, it would serialize itself into a data stream and the adapter would send it to the appropriate server. If the class used a DatabaseStorageAdapter, it would bind the object's variables to an SQL statement and execute the statement directly to the database (Oracle, Sybase, et al).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.