Abstraction in C++!!

Data abstraction is one of the most essential and important feature of object oriented programming in C++. Abstraction means displaying only essential information and hiding the details. Data abstraction refers to providing only essential information about the data to the outside world, hiding the background details or implementation.

Consider a real life example of a man driving a car. The man only knows that pressing the accelerators will increase the speed of car or applying brakes will stop the car but he does not know about how on pressing accelerator the speed is actually increasing, he does not know about the inner mechanism of the car or the implementation of accelerator, brakes etc in the car. This is what abstraction is.

Abstraction using Classes: We can implement Abstraction in C++ using classes. Class helps us to group data members and member functions using available access specifiers. A Class can decide which data member will be visible to outside world and which is not.

Abstraction in Header files: One more type of abstraction in C++ can be header files. For example, consider the pow() method present in math.h header file. Whenever we need to calculate power of a number, we simply call the function pow() present in the math.h header file and pass the numbers as arguments without knowing the underlying algorithm according to which the function is actually calculating power of numbers.

Abstraction using access specifiers

Access specifiers are the main pillar of implementing abstraction in C++. We can use access specifiers to enforce restrictions on class members.
For example:
Members declaredpublic in class,can be accessed from anywhere in the program.
Members declared as private in a class,can be accessed only from within the class.They are not allowed to be accessed from any part of the code outside the class.
Advantages of data Abstaction
1)Helps the user to avoid writing the low level code 
2)Avoids Code duplication and increases reusability
3)can change internal implementation of class independently without affection the user
4)Helps to increase security of an application or program as only important details are provided to the user.
Disadvantage of Abstraction:
The main issue is loss of context.Using and over using abstractions can cause developers to cease to determine the context of use of an abstraction.

The extra code needed to fully implement an abstraction adds linecount and ultimately code size and if the code isn't carefully implemented can end up"pulling in"lots of extra code,leafing to overlarge run time executables and ultimately making the device itself more expensive.
Posted on by