Home > Programming > Abstraction

Abstraction

A few things can confuse programming students, or new people to programming. One of these is abstraction.

Wikipedia says:

In computer scienceabstraction is the process by which data and programs are defined with a representation similar to its meaning (semantics), while hiding away the implementation details. Abstraction tries to reduce and factor out details so that the programmer can focus on a few concepts at a time. A system can have several abstraction layers whereby different meanings and amounts of detail are exposed to the programmer. For example, low-level abstraction layers expose details of the hardware where the program is run, while high-level layers deal with the business logic of the program.

That might be a bit too wordy for some people, and not at all clear. Here’s my analogy of abstraction.

Abstraction is like a car

A car has a few features that makes it unique.

  • A steering wheel
  • Accelerator
  • Brake
  • Clutch
  • Transmission (Automatic or Manual)

If someone can drive a Manual transmission car, they can drive any Manual transmission car. Automatic drivers, sadly, cannot drive a Manual transmission drivers without “relearing” the car. That is an aside, we’ll assume that all cars are Manual transmission cars – as is the case in Ireland for most cars.

Since I can drive my car, which is a Mitsubishi Pajero, that means that I can drive your car – a Honda Civic, Toyota Yaris, Volkswagen Passat.

All I need to know, in order to drive a car – any car – is how to use the breaks, accelerator, steering wheel, clutch and transmission. Since I already know this in my car, I can abstract away your car and it’s controls.

I do not need to know the inner workings of your car in order to drive it, just the controls. I don’t need to know how exactly the breaks work in your car, only that they work. I don’t need to know, that your car has a turbo charger, only that when I push the accelerator, the car moves. I also don’t need to know the exact revs that I should gear up or gear down (although that would be better on the engine!)

Virtually all controls are the same. Standardization means that the clutch, break and accelerator are all in the same place, regardless of the car. This means that I do not need to relearn how a car works. To me, a car is just a car, and is interchangeable with any other car.

Abstraction means not caring

As a programmer, or someone using a third party API (for example), abstraction means not caring how the inner workings of some function works – Linked list data structure, variable names inside the function, the sorting algorithm used, etc – just that I have a standard (preferable unchanging) interface to do whatever I need to do.

Abstraction can be taught of as a black box. For input, you get output. That shouldn’t be the case, but often is. We need abstraction so that, as a programmer, we can concentrate on other aspects of the program – this is the corner-stone for large scale, multi developer, software projects.

Abstraction is not like Peter Sarstedt’s Where Do You Go To My Lovely.

You talk like Marlene Dietrich
And you dance like Zizi Jean-Maire
Your clothes are all made by Balmain
And there’s diamonds and pearls in your hair

You live in a fancy apartment
Off the Boulevard St. Michel
Where you keep your Rolling Stones records
And a friend of Sasha Distel.

You go to the embassy parties
Where you talk in Russian and Greek
And the young men who move in your circles,
They hang on every word you speak.

But where do you go to my lovely…
When you’re alone in your bed.
Tell me the thoughts that surround you.
I want to look inside your head.

I’ve seen all your qualifications
That you got from the Sorbonne
And the painting you stole from Picasso.
Your loveliness goes on and on.

When you go on your summer vacation,
You go to Juan-les-Pins
With your carefully designed topless swimsuit

You get an even suntan
On your back and on your legs
And when the snow falls you’re found in St. Moritz
With the others of the jet set

And you sip your Napoleon brandy,
But you never get your lips wet

But where do you go to my lovely…
When you’re alone in your bed.
Tell me the thoughts that surround you.
I want to look inside your head.

You’re in between twenty and thirty,
A very desirable age.
You’re body is firm and inviting,
But you live on a glittering stage.

Your name it is heard in high places.
You know the Agha Khan.
He sent you a race horse for Christmas
And you keep it just for fun, for a laugh, aha aha.

They say that when you get married,
It will be to a millionaire.
But they don’t realize where you came from
And I wonder if they really care, or give a damn.

But where do you go to my lovely…
When you’re alone in your bed.
Tell me the thoughts that surround you.
I want to look inside your head.

Ah, remember the back streets of Naples,
Two children begging in rags
Both touched with a burning ambition
To shake off their lowly-born tags, so they try.

So look into my face Marie-Claire
And remember just who you are.
Then go and forget me forever
But I know you still bear the scar deep inside, yes, you do.

Ah, I know where you go to my lovely…
When you’re alone in your bed.
I know the thoughts that surround you,
Cause I can look inside your head.

 

TOP