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
  • 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.
7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

607 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