Abstraction
Learn to hide the data with the abstraction technique in OOP.
Definition
Abstraction is a technique used in object-oriented programming that simplifies the program's structure. It focuses only on revealing the necessary details of a system and hiding irrelevant information to minimize its complexity. In simpler words, we can say that it means to show what an object does and hides how it does it.
Example
There are countless real-life examples demonstrating the principle of abstraction. Consider the “volume” button on a television remote. With one click, we can increase the TV’s volume. Internally, this button might call a function like volumeUp()
. The TV then responds by producing louder sound. As users, we don't need to know anything about the internal circuitry or mechanism. We simply know that pressing the button increases the volume.
Another example is our everyday use of vehicles. Pressing the accelerator pedal signals the car to increase its speed by consuming more fuel. We don't need to understand the detailed mechanical processes involved; we only interact with the simplified interface provided to us.