Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2306
  • Last Modified:

OOPS terms

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
sctt_tiger
Asked:
sctt_tiger
  • 2
  • 2
  • 2
  • +2
2 Solutions
 
evilrixSenior Software Engineer (Avast)Commented:
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
 
Infinity08Commented:
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
 
Infinity08Commented:
Heh, seems I'm quite a bit slower in typing lol.
0
Technology Partners: 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!

 
itsmeandnobodyelseCommented:
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
 
trinitrotolueneDirector - Software EngineeringCommented:
0
 
trinitrotolueneDirector - Software EngineeringCommented:
0
 
dmxflamesCommented:
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
 
evilrixSenior Software Engineer (Avast)Commented:
>> 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now