OOPS terms

Posted on 2009-04-15
Medium Priority
Last Modified: 2012-05-06
hello experts,
i am learning C++.
please tell me what is difference between Data Abstraction, Data hiding and data Encapsulation.

Also, please, does C support Data Abstracion ?
Question by:sctt_tiger
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
LVL 40

Accepted Solution

evilrix earned 100 total points
ID: 24147842
Some general OOP terms defined...

-          Inheritance

Means to derive behaving from a more generic type and implement a specialization of that type. For example, if we have a class called animal and we sub-class that to create a class called cat we have inherited all the behavior of an animal and then extend it to add behavior specific to a cat.

-          Abstraction

An abstraction is a generalization of something. For example we might be writing a game that has a boxer and a sumo wrestler, both of tese could derive from an abstract class called fighter. The class fighter is an abstraction of the basic ingredients required to represent a fighting character, which must then be sub-classed (see inheritance) to provide the more specific specialized behavior. The fighter class might not even implement any functionality, it might just provide an interface that all fighter types must implement. If your fighter class is well defined you can interact with any sub-class (boxer, wrestler, kung-foo master) via the abstract class interface.

-          Polymorphism

This is the ability for a type to be used within the context of its base class type yet the compiler will automatically perform the behavior of the sub-class type it refers to. For example, you make have a class of type boxer, which if currently pointed to by a pointer of the abstract fighter type. When you call the punch() method on fighter, which is an abstract method, the compiler will ensure that what actually happens is that the punch method for the boxer is called.

-          Encapsulation
This is information hiding, you might have a car and you know how to start the car, turn the wheels, accelerate and break. You know how to do this through a simple interface, you don't need to know how it all works, the detail of this is hidden from you. Because of this the maker of the car and change how their car works so that their next model has a completely different engine and other parts, but the interface is identical (steering wheel, breaks etc..) so you can still drive it. If you interacted with the detail and they changed it you'd have to re-learn how the new car worked!

Data-hiding is an artifact of abstraction and encapsulation. It's where we prevent objects from outside a class knowing anything about the class internals.

More info: -


LVL 53

Assisted Solution

Infinity08 earned 100 total points
ID: 24147989
data abstraction : a distinction is made between the (abstract) interface of a data type, and its (concrete) implementation. The user of the data type will interact with it using the provided interface, and the implementation will be hidden from the user.
Look at it as a black box (http://en.wikipedia.org/wiki/Black_box) : all you need to know is how to use it - how it works internally is not relevant.

data hiding : any part of the code should only have access to that data that it needs to use. Hiding all data that it doesn't need, makes sure that it can't inadvertently modify it either.

data encapsulation : making the class member data private, and only allowing manipulation of that data through well defined class methods.

You'll notice that these terms are very similar. That is because they deal with related issues. But they're not exactly the same, as I hope you can see from the above definitions.

>> Also, please, does C support Data Abstracion ?

Sure. Not in exactly the same way as an object oriented language of course, but data abstraction does exist. You can use pointers and structs to abstract data for example.
LVL 53

Expert Comment

ID: 24148011
Heh, seems I'm quite a bit slower in typing lol.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 39

Expert Comment

ID: 24151501
For 'data abstraction' I found at Wikipedia (http://en.wikipedia.org/wiki/Data_abstraction)

the mechanism and practice of abstraction reduce and factor out details so that one can focus on a few concepts at a time.


abstraction - a concept or idea not associated with any specific instance


Data abstraction allows handling data bits in meaningful ways. For example, it is the basic motivation behind datatype.

The (3) is similar to that what Infinity said. And (1) may express somewhat like  the 'generalization' issue evilrix mentioned.

For 'data hiding' I found:

Information hiding in computer science is the principle of hiding of design decisions in a computer program that are most likely to change, thus protecting other parts of the program from change if the design decision is changed. The protection involves providing a stable interface which shields the remainder of the program from the implementation (the details that are most likely to change).

Here evilrix seems to have the same focus on the fact that the main benefit of data hiding is to being able to change or improve an implementation without having to change the usage.

And finally for 'encapsulation'

encapsulation is the hiding of the internal mechanisms and data structures of a software component behind a defined interface, in such a way that users of the component (other pieces of software) only need to know what the component does, and cannot make themselves dependent on the details of how it does it. The purpose is to achieve potential for change: the internal mechanisms of the component can be improved without impact on other components, or the component can be replaced with a different one that supports the same public interface.

Encapsulation also protects the integrity of the component, by preventing users from setting the internal data of the component into an invalid or inconsistent state.

The second part is that what Infinity has told about data hiding. The 'private members' surely is a C++ specific way of encapsulation. Both Infinity and evilrix also mentioned the near relationship of 'data hiding' and 'encapsulation'.


Expert Comment

ID: 25413797
Much has been already nicely described...


  1. Data abstraction involves resolving "real-world" information to a programmable form involving data structures.
  2. Data hiding is restricting data for use by code (as descibed also by Infinity 08)
  3. Data encapsulation concerns defining access scopes to data in objects so as to provide a safe-way in dealing with data. This is most useful for properties of classes that need controlled external access. In particular, public 'setters' and 'getter' are used to expose and access field members which have been scoped private.

LVL 40

Expert Comment

ID: 25419004
>> Data hiding is restricting data for use by code (as descibed also by Infinity 08)
I think you'll find he wasn't the only one who mentioned this.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question