473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

understanding of data abstraction, information hiding and encapsulation

Is my following understanding correct ?

Data abstraction means providing the interface - that is, the set of
functions that can be called by the user of a class.

Information hiding means mentioning the class members(functions,
typedefs, data) under the access control labels : public, protected,
private.

Encapsulation means providing the implementation of class member
functions and the implementation is hidden except for the inline
functions which can be present inside the class definition or the
header file which are visible to the user of a class.

Kindly correct me if my understanding is wrong. Wherever I have gone
wrong, please provide an example C++ class so that I can understand.

Also, does the process identification of class, its member functions
and data members, class objects, fall under data abstraction ? If not,
what is it called.

Kindly explain.

Thanks
V.Subramanian

Sep 25 '07 #1
2 7598
On 2007-09-25 06:42, su**************@yahoo.com, India wrote:
Is my following understanding correct ?

Data abstraction means providing the interface - that is, the set of
functions that can be called by the user of a class.
Yes.
Information hiding means mentioning the class members(functions,
typedefs, data) under the access control labels : public, protected,
private.

Encapsulation means providing the implementation of class member
functions and the implementation is hidden except for the inline
functions which can be present inside the class definition or the
header file which are visible to the user of a class.
The way I see it information hiding and encapsulation are more or less
the same thing, and it means that the user of the interface does not
know (or at least do not need to know) how the functionality provided by
the interface is implemented.

What this means is that when you have defined the interface and written
the code to support it a user should be able to take the code and start
using it. Later you should be able to completely replace the
implementation with a new one that provide the same interface and the
user should not have to make any changes to his/her code.
Kindly correct me if my understanding is wrong. Wherever I have gone
wrong, please provide an example C++ class so that I can understand.
A good example is the use of inheritance to define an interface and then
allow different implementations in derived classes:

#include <iostream>

class Twice
{
public:
virtual unsigned int twice(unsigned int i) = 0;
};

class ShiftTwice : public Twice
{
public:
unsigned int twice(unsigned int i)
{
return i << 1;
}
};

class MultiplyTwice : public Twice
{
public:
unsigned int twice(unsigned int i)
{
return 2 * i;
}
};

int main()
{
Twice* ss = new ShiftTwice();
Twice* ms = new MultiplyTwice();

std::cout << ss->twice(4) << "\n";
std::cout << ms->twice(4) << "\n";

delete ss;
delete ms;
}

Since both ShiftTwice and MultiplyTwice have the same interface they can
be used interchangeably as long as we access them through a pointer (or
reference) to Twice.
Also, does the process identification of class, its member functions
and data members, class objects, fall under data abstraction ? If not,
what is it called.
I am not sure what you are talking about, perhaps runtime type
information, but that have nothing to do with any of the above.

--
Erik Wikström
Sep 25 '07 #2
On Sep 25, 7:42 am, "subramanian10...@yahoo.com, India"
<subramanian10...@yahoo.comwrote:
Is my following understanding correct ?

Data abstraction means providing the interface - that is, the set of
functions that can be called by the user of a class.

Information hiding means mentioning the class members(functions,
typedefs, data) under the access control labels : public, protected,
private.

Encapsulation means providing the implementation of class member
functions and the implementation is hidden except for the inline
functions which can be present inside the class definition or the
header file which are visible to the user of a class.

Kindly correct me if my understanding is wrong. Wherever I have gone
wrong, please provide an example C++ class so that I can understand.

Also, does the process identification of class, its member functions
and data members, class objects, fall under data abstraction ? If not,
what is it called.

Kindly explain.

Thanks
V.Subramanian
Hi V. Subramanian
I think your understanding about these OO concepts are relatively
correct. My main reference for OOA/D/P is the book by Booch: Object-
Oriented Analysis, Design and Applications, 2nd edition, 1994. Of
course the 3rd edition just published.
1. Abstraction
According to Booch, Abstraction is first and most important concept in
Object Model. Abstraction means focus on more important charactristics
of a concept and ignore less important ones from the point of viewer.
Abstraction focust the outside view of an object/concept. As an
example, consider the vector in standard library. You want to create a
vector with a given size (constructor), enlarge or grow the vector
(push_back), accesing to elements (operator[]) and ... It is less
important how to implements the vector internelly. You may use vector
for years, but you probably don't know how vector is implemented.
2. Encapsulation
Encapsulation is a complementary concept to Abstraction. For effective
use of Abstraction, the implementation of an object should be hidden.
It means encapsulation guarantees abstraction is used only through
operations (or C++ member functions and some related non-member and
friends functions). Consider again the vector. You can use vector
effectivly through its member functions. For using it, you don't have
to know the details of representation (data members) of vector.
Encapsulation focus on the inside view od an object/concept.
3. Information hiding
It is another term for encapsulation. You hide the data or information
from direct manipulation.

For detailed description of these concepts refer to Booch 2nd edition
and The C++ Programming Language 3rd edition by B. Stroustrup.

At last some simple notes:
1. For information hiding you usually put data members under private
and protected access control.
2. Inline has no relation to information hiding.
3. Encapsulation is for code not people.

Regards,
S. Amrollahi

Sep 25 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Lorenzo Villari | last post by:
I premise I don't know C++ well but... I wondered what is this data hiding thing... I mean, if I can look at the header (and i need it beacuse of the class), then what's hidden? Can someone give...
2
by: coolwarrior | last post by:
Hi, 1_I want to know the difference between "data hiding" , "steganography" ,"watermarking" ,"capsulation" related to DSP. 2_There r plenty of informaion about data hiding for images on the web...
12
by: Alex Hunsley | last post by:
There's no really specific questions in this post, but I'm looking for people's thought on the issues within... The two main versions I've encountered for data pseudo-hiding (encapsulation) in...
2
by: Neo | last post by:
I was written this code; in VS2k5 class Program { private: int a;
63
by: time.swift | last post by:
Coming from a C++ / C# background, the lack of emphasis on private data seems weird to me. I've often found wrapping private data useful to prevent bugs and enforce error checking.. It appears...
11
by: sofeng | last post by:
I'm not sure if "data hiding" is the correct term, but I'm trying to emulate this object-oriented technique. I know C++ probably provides much more than my example, but I'd just like some feedback...
1
by: subramanian100in | last post by:
I am a beginner in C++. I come across the terms data abstraction and encapsulation in C++. I am unable to understand the definitions. Kindly explain these terms with a simple example in C++ ...
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
2
by: jitendra kumar rathi | last post by:
" it facilitates the object to hide its implementation and expose only interfaces" this above line is for encapsulation or abstraction??? and how?????? my next question is that- ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.