Abstraction in OOPs
Today we will have a deep thought on what exactly is abstraction in programming world. Lets first try to understand the abstraction in generic terms. In generic terms meaning of abstraction is "the quality of dealing with ideas rather than events"or"something which exists only as an idea"or"the process of considering something independently of its associations or attributes".
So basically from all meanings we can conclude that its overall an idea and not a rigid thing (implementation). Abstraction is used in all of the processes that we met in our day to day life. In simple terms we can understand it as layering (or extraction) from work done to provide a crisp and final result that could be easy to use for the person (or process) above the layer.
e.g: While learning a car you will be only concerned about learning how to drive, or how much you should bend the handle to take a turn or how much you should press the accelerator to speed up to rush to your work. You don't damn care about the how many time the piston pumps the engine, or how much spark is generated to produce force, or how much friction is required to apply brakes with brake shoe. So, that's what abstraction is. You only take the things of your concern, or car company provide the interface to use that is only of your concern. You just need to turn key in ignition and car will start, you doesn't need to understand 'how'.
Now lets try to understand the abstraction in programming world. In object oriented programming we use some concepts and implementations to achieve abstraction. We use Encapsulation, Inheritance and data hiding to achieve abstraction in programming world. Abstraction is not something that can be implemented on code, its only in our mind it can only be achieved in thought.
Encapsulation is an Object Oriented Programming concept that binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse. Data encapsulation led to the important OOP concept of data hiding.
In object-oriented programming, inheritance enables new objects to take on the properties of existing objects. A class that is used as the basis for inheritance is called a superclass or base class. A class that inherits from a superclass is called a subclass or derived class.
Now lets understand how inheritance help us to achieve abstraction. Interfaces and abstract classes are used to achieve abstraction. Lets suppose you have created a system or a library and you want to expose some functionality that you want your consumer to use, and you also want a loose coupling between your code and client usage so to leave a scope for change to your implementation in future.
For above like scenario we expose interfaces to our client so that we would be able to update its concrete implementation if required in future without affecting the code done by client.
e.g- Your office administration installed a coffee machine in your office, and it was told to everybody that pressing 'make coffee' button on that machine will make a cup of coffee for you. After some days admin's got a better upgrade to that machine which makes coffee by crushing fresh beans, they just replaced the internal machine with the upgraded version. But still you didn't have to change anything, it works the same way as it was, pressing 'make coffee' button is making a cup of coffee to you but with better added taste. So this is what we call loosely coupled or indirectly 'abstraction'. You don't know, or even bother what going on inside that machine or what has been changed, but it still works for you in same way.
Comparing it with programming world, you created a coffee system and exposed an interface that has a method makeCoffee(). Client will use this method to solve its purpose. But you can upgrade the implementation of makeCoffee() with time to provide better output. So using interfaces we need inheritance to provide concrete implementation to solve the purpose. In Interface we abstract the idea of making coffee, and let the details of implementation aside.
Abstraction is hiding of extra complexity of features in real world. Data hiding is term that we use in programming world. Hiding the implementation to provide a simplified interface for ease of usage. It not hiding the source code from others. You cannot directly say that data hiding is abstraction or vice versa. Abstraction not merely hiding data but its whole oriented around providing easiness to usage.
Abstraction differs with the perspective of the user. As per above coffee machine example, for machine user - the abstraction is from details of internal working of the machine, for a machine repairer - its from the chip set that is being used to count the coffee cup, and the sensor that check temperature before making coffee and for a chip maker it doesn't matter in which company machine it will be used as that chip will do what it is programmed to do. Here we can see abstraction on three different layer of process. That is why we say abstraction is "something which exists only as an idea".