C++ Abstraction

Abstraction is a mechanism to represent only the essential features and hide irrelevant details so that one can focus on important things at a time. For example, while driving a car, a driver only knows the essential features to drive a car such as pressing the accelerators will increase the speed of the car or applying brakes will stop the car and least bothers about the internal details of accelerator, brakes etc in the car.

There are two types of abstraction

  • Data abstraction: it represents essential features without including background Details.
  • Control abstraction: It means hiding the implementation details.

Data abstraction can be implemented through

  • Abstraction using classes and objects
  • Abstraction using header files

Abstraction using classes and objects

Classes are used to group all data members and members function of that class bind into a single unit. Classes can be used to determine which data member can be visible outside and which is not.

Abstraction using header files

One more type of abstraction is header file.For example Consider strlen() function present in string,h header file used to calculate the string length without actually knowing the underlying algorithm according which the faction is actually calculating the length of the string.

ACCESS SPECIFIERS IN ABSTRACTION

Public Label :

When the member declared public in a class. It means that member of that class can be accessed anywhere from the program.

Private label :

When the member declared private in a class. It means that member of that class can be accessible within the class. It cannot be accessed from outside of that class.

  • Data Abstraction helps in reusability of that code and avoid the code duplication.
  • It helps to avoid writing the low-level code.