Abstraction mean to implement or program a class, package, library or whole software in such a way that it only expose some high-level functionality or mechanism for using it.

Here package and library terms might be new for you. We will discuss these at end of our course in detail. But for now, you should assume these as a group or bundle of multiple classes that are suppose to perform same functionality or solve a problem.

You can think of Abstraction as an extension of Encapsulation. Encapsulation usually represent restricting direct read or write access to state of an object. But, abstraction ask you to only expose basic set of those properties/attributes and functionality that are require to use that object in a program, and hide all other details.

Let’s take an example to better understand this. Let’s assume you want to write a car simulator program or a racing game.

Let’s assume you write a class ‘Car’ to represent a high level object of car in your computer program. And you want to expose only two functions to all other objects and modules of your program that can be used to operate that car. Those two functions can be Move and Turn.

You might have to write two very complex class methods or a complete package to control acceleration and speed of car, and to turn while moving forward or backward. But, other objects or modules will just see two simple function calls with some basic parameters. Let’s say a ‘move’ function that will accept only one parameter to determine direction that is to move forward or backward. And ‘turn’ function will also accept one parameter to turn either left or right.

In real world we can take example of a real car. We use car accelerator to move our car, we use our foot pressure to control acceleration or speed. And we use steering wheel to turn our car. We don’t really know and need to know complex system and working of complete car, acceleration and steering. Because, we are only concerned about simple mechanism for using a car. This is abstraction in our real life, where car manufacturer hide all complexities of different parts and operations and provide us just basic control to use a car.

If you still have any confusion on this, please ask your questions as comments below.

Let’s move on to our next chapter to discuss another important topic of Object-Oriented Paradigm. Please click on ‘Next’ to continue.

Image placeholder

Hi! I'm Zeeshan Elahi

I have compiled and prepared this content with love for people like me and you. And as you know it always take some time and extra cups of coffee to read, compile and prepare a course or manual. If you have like reading this content and want to say thanks, please consider supporting from more stuff like this.

Leave a comment

Your email address will not be published. Required fields are marked *