Solved

OOPS terms

Posted on 2009-04-15
9
2,285 Views
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 ?
0
Comment
Question by:sctt_tiger
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 25 total points
Comment Utility
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: -

http://en.wikipedia.org/wiki/Object_oriented
http://www.cplusplus.com/doc/tutorial/polymorphism.html

   
0
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 25 total points
Comment Utility
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.
0
 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
Heh, seems I'm quite a bit slower in typing lol.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
Comment Utility
For 'data abstraction' I found at Wikipedia (http://en.wikipedia.org/wiki/Data_abstraction)

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

and

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

and

(3)
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'.


 
 
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 12

Expert Comment

by:trinitrotoluene
Comment Utility
0
 
LVL 12

Expert Comment

by:trinitrotoluene
Comment Utility
0
 

Expert Comment

by:dmxflames
Comment Utility
Much has been already nicely described...

Simply:

  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.


0
 
LVL 40

Expert Comment

by:evilrix
Comment Utility
>> 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.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now