A
bstraction means to hide the internal details and show only essential features
to the user which is required to be known by him in order to operate the system.
Consider an example of TV. It has various features like changing the channel, volume
control, ON/OFF switch etc. Various interfaces are provided to the user so that
he can operate the TV, like channel changer, volume controller, power button etc.
Thus the user knows the interfaces to control the functionality of the TV but he
does not know how these interfaces are working internally i.e. the internal details
of the interfaces. The internal detailed functionality of the TV is kept hidden
from the user. He is just provided only with the essential features so that he can
operate the TV. So a non-technical person can operate the TV easily. This is the
concept of Abstraction.
Similarly in case of OOPs classes use the concept of abstraction. A class contains
data and functions to operate on that data. The user is provided with the interfaces
i.e. function names to operate on data but he does not know how the function is
being implemented internally.
For example:
Suppose there is one data member ‘a’ in the class. There is a member function ‘square
( )’ in the class. This function is calculating the square of ‘a’. User knows that
the function ‘square ( )’ is calculating square of the value provided by him in
‘a’. But he does not know the implementation details of the function i.e. the function
can find the square using any of the following ways-
a * a OR
pow(a,2) OR
a+a+a+a
But the user will not know that which method is being used. Thus the concept of
abstraction is being implemented.
Abstraction is useful both to the user as well as to the programmer of the class.
User does not have to know the complex implementation details of the function and
the programmer can make any change in the implementation of the function without
changing the interface i.e. function name.