Object Oriented Programming - Abstraction


Abstraction is a concept which facilitates to extract out the essential information of an object.

In OOP ( Object Oriented Programming ) , Abstraction facilitates the easy conceptualization of real world objects into the software program.

Abstraction lies everywhere! What ever you see, do and live are all full of abstraction.

In mathematics, multiplication is a kind of abstraction. The symbol "x" is an abstract symbol that can do multiplication of any two elements.

2 x 3 = 6
3.5 x 3.7 = 12.95
(a + b) x ( a - b) = a^2 - b^2

In Art, Abstract Art is a kind of art, which depicts the distilled form of the world.

Courtesy: RegiaArt

So, what exactly an Abstraction is?

Abstraction facilitates the easy conceptualization of real world objects, by eliminating the unnecessary details of the object. Unnecessary details? Yes, all the similar objects when you generalize, you will drop the uncommon details about the objects.

E.g., when you model a generic prototype for CRT Television & a Plasma Television, you look for details like Type of screen, Height, Width, thickness etc.; these are necessary details for a Television. But a Television object doesn’t need to have details of what kind of Electron it will bean to power the CRT, what kind of liquid plasmas it will use to power the Plasma TVs. These kinds of details are unnecessary details.

Let’s take mobile phone as the real world example. Look at the below mobile phones.

What do you feel about them?

  • Firstly, everything is Nokia Mobiles
  • You could see Slide, Flip and Bar models
  • You could see Music, Business & 3G Mobiles
  • You could see QWERTY , Basic and No keypads
  • You could extra music player button on music edition.
  • The Color, Size, Weight, Look etc...
  • And even more…

So, for better understanding I organize the mobile phones in the below format.

Basically, all the mobiles belong to Nokia.

Still need a better classification, I drill down to its features and conceptualize the mobiles in more general way. So, you could categorize the mobiles as

  • Music
  • Business
  • Gaming
  • Normal
  • 3G

As a layman user, you will feel its weight, color, style. As a music lover, you will check for the memory, type of media files it supports, and type of communication between devices (Bluetooth, Wi-Fi etc). As a business person, you will check for the memory, type of business application etc.

Now, you have got the details of the each and every mobile. It's time to extract the most essential details of these mobile categories. Here I use an Abstraction filter, which abstracts out the essential details. So, essential details, here I mean is the most common properties of the mobiles.

So, now the conceptualization of mobile has still got finer. Now you can still go deep and get a finer concept to model a generic / abstract mobile, which can be turned into a beautiful mobile of your kind.

Now, you have extracted out the necessary details for each category of mobile. You still fine grain it to get a mobile phone's basic property with the Abstraction filter.

Now, here comes your basic design of the Nokia mobile phone. You have learnt how you will abstract properties from the real world objects. Now the question is how you do it in the programming language. In the Object oriented principles, abstraction is achieved via Inheritance (a widely used design pattern)

The class diagram for the Nokia mobile using Inheritance look like below

You would have missed to understand the abstraction in the computer science. Here are few places where you could see how the abstraction works

  • Network Layers – OSI Model
  • Database Architecture – Data Abstraction ( Physical, Logical , View )
  • Polymorphism – Abstraction of Actions / Methods
  • Templates in C++ or Java – Abstraction of Common Objects
  • Data Structures – Abstract way to store & retrieve the data
  • Many more…

One important thing you need to remember is ‘Abstract objects’ never exists in real world. It is just the concept that we build to understand the working of real world objects.

E.g., There is nothing is called a Television, you have CRT Television (this is known commonly as TV), Plasma TV or LCD TV.

Published on: