sir my doubt is about data abstraction.data abstractio means representing essential features with out back ground details.ex:if we give two numbers for addition computer performs addition and gives result.here we do not know how computer stores integers,how addition is performed?.
abstaction is a feature of c++.then my doubt is  how abstraction is achieved in a class?
which back ground details are hidden  in a class?which essential features are shown?please explain with a class.

Hello phaneendra

You are correct about the integer example of data abstraction. When we do not care about how the data is stored, the integer is an abstract data type. Classes can also hide implementation details so they too can be used for abstraction. Of course, they are abstractions only to the users of the class. They are not abstractions to the programmers which are creating the class.

For example, in C++ we have many container classes to store data. One such class is the vector. It is like an array. As a user of the vector, all I need to know is that I can add elements to the end of the vector, and get any element from the vector. I do not care about how the vector stores the elements or how the vector manages space for the elements.

Another example is the idea of using streams to get data. You can use a stream object to get data from a file or from a keyboard. The data is thought of as a stream of bytes without concern about where the data came from. Your program can be written to use a single istream object, and not care about if the object is reading from the keyboard or file and certainly not care about how file access or keyboard access is done.

For my last example, consider a banking application which needs to control automatic bank machines (ABMs) which give out cash. Such an application would need to open communication channels to an ABM, create command messages of the type the ABM understands, and send the messages to the ABM. A bad design would have all that code spread throughout the banking application. A good design would hide all those details into an ABM class. The rest of the application would access the ABM functions through higher level functions such as "dispenseCash" or "goOutOfService". All the communication details and message formatting details are abstracted out and hidden in the ABM class. Such a design could accept new ABM models easily. A programmer would create a new ABM class with the same functions, and the rest of the banking application could use it without any further code changes.

I hope those examples make the idea clearer.
Best regards


All Answers

Answers by Expert:

Ask Experts




No longer taking questions.


No longer taking questions.

No longer taking questions.

©2017 About.com. All rights reserved.