Skip to main content

C++ Abstraction

Abstraction is important features of object oriented programming (oops). abstraction means provide and showing essential features. And hide that its implementation detail and background process.

Class are provide abstraction in C++. there are combining of data member and member function. In this case access specifiers are providing accessibility of data member and functions. In this situation are abstraction is applied. for example how to actual hide data using access specifier. and which algorithm and process are do this task. we are only know about access specifiers behaviors.

Real life example

In this modern epoch, everyone are using commonly mobile phones. assume that you are purchase a mobile phone. So before purchase we are checking of all the specification of different different mobile phone. like operating system, RAM, internal storage, better camera, fingerprint, display, color,Security, Battery ,price, brand so on. And selected one mobile which best in quality and feature. But note that they only essential information. Not given all implementation details. like how to sensor are implemented, how to developing (implementation) operating system for mobile. how to mobile are received calls. which algorithm are used to upgrade operating system. and similar many more process.

abstraction are used to security purpose. if given all implementation detail so there can possible anyone break security.

Example of data abstraction

Class are provide abstraction using of access specifiers. That are provide restriction to use data member and member function of outside of class. and also control accessibility of inherit class.

using namespace std;
class Safety{
  //access specifiers
  //private data member 
  int rupee,dollar;
    //member function
    void display();
Safety::Safety(int rupee,int dollar){
  //assign value of private data member
void Safety::display(){
  //display private data within member function 
  cout<<"rupee :"<<rupee<<endl;
int main(){
  //create object to class
  Safety coin(70,34);
  Safety cent(90,24);
  //display data member
rupee :70
rupee :90

Note that public function are accessible by class object outside of class. and private and protected data and function are accessible (usable) by only within member function.

So what is abstraction of this case?. Here abstraction are class and its access specifiers. We are no knowledge about which algorithm of used to implement class and class access specifier. we are know about that how to use class feature in our program. but never information about that how to internally that are implement and which process are do this task.

Designing Strategy

Abstraction are protected designing strategies of any organization and programming language. because there are two main reason. number one is protection of unwanted use. and another is that, is not important for all human beings.

for example almost every people are used ATM machine but there are transaction are work only when provide valid ATM card and pin and also amount are available on your account. assume that ATM administer are providing complete information about that ATM machine. like that it's design pattern, algorithm, security check system, circuit design, its parts, and its blue print. then there are possible to braking those security are very easy. So this information are not important for every human beings.


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment