What is an abstraction in programming and why it is important?

Abstraction is one of the most important concepts in programming. It is hard to write quality code in a programming language without a deep understanding of this concept.

Abstraction is: “the purposeful suppression or hiding of some detail of a process or artifact in order to bring out more clearly other aspects details or structure” Timothy A. Budd.

Informal overview: a real-life example


Let’s see an example of how we use abstraction daily.
Think for a moment, what is a cellphone for you?

Usually, you will get something like this as an answer: a cellphone is an electronic device. You can input cellphone numbers and make calls. Also, cellphones have a screen and a battery.

The previous information is enough to use a cellphone. We don’t need more details on the components for us to use it. For instance, we don’t need to know the material that was used to build the phone.

If we try to draw what we understand for a cellphone, we can see something like the picture below.

example of what is an abstraction

The figure above shows us a model that we created in our mind about what a cellphone is. This model is enough for us to have a good understanding of how to use a cellphone.
As you can see now, we use abstractions daily.
For instance, what is a:

  • boat?
  • car?
  • building?

Your understanding of the previous objects from the real world is an abstraction. I don’t know everything that is inside of an aeroplane or a boat.

We don’t know the materials that someone used in a building but still, we can use them.

We can go to a building and have an office or live there or we have a car, although we don’t know how the engine was built.

In the real world, we only need a basic understanding of how we can use them.

That is what we do in programming. We create models of the real world (sometimes about things that does not exist in the real world). We implement these models in a specific programming language to solve a problem. Also, we ignore everything unnecessary for the solution of the problem we are trying to solve; and we hide from the user’s everything that they don’t need to know to use the software we created.

Levels of abstraction

As part of the software development process, we have to deal with different levels of abstractions.
There are several roles in a software development team. They can change according to the software development methodology that the team is using. Let’s say we have the following roles:

  • Project leader
  • Project architect
  • Designer
  • Database manager

People in these roles have a different view of the same software. If you talk to the project leader, he/she probably won’t know implementations details. But if you ask the architect, it will have those details.
What is the meaning of this?
Software development team members create abstractions in the same we do it in or life. Their output will be according to the role they have in the project.

Abstractions in programming/software development

From the previous section, we can infer that each person participating in the project have to create their models. But how this will happen?

At the beginning of the project, we should only create high-level abstractions. We have to omit implementations details as much as we can.
More details can be added to the models as a next step in the process. We can also create different types of models. It allow us to add more details as they are needed.

A simple example will be if we use UML (and a methodology). We probably will start with a use cases model.
In a use case model, you will have to specify which are the stakeholders (entities or people that will interact with the software), and the functionalities the software will have.

At that point, you usually didn’t decide what platform (programming language, operating system, etc.) you will use for the development. There is no need for that during that stage.

After that, you start creating other models: class diagrams, sequence diagrams, etc. Those diagrams are also independent of the programming language. But at this stage, you already specify what classes will be implemented as part of the software and how they will interact.

At another stage, you will start designing the user interfaces. Here you will start seeing how your software will look like for the user. At this stage, you added more details to the model you are creating to give solution to a problem.
As you can see, you create the model step by step. You add more information to the model according to the needs, until you have a fully functional software.

If you think about the end-user, he/she won’t know anything about most of those models. The end-user only needs to know how to interact with the software. It will only want to know about the user interface.
For that user, the software will be the user interface and what the software can do for him/her.
For the software development team, the software is something else.

Summary

Abstraction is one of the main concepts in programming. It does not matter whether you are using OOP or functional programming; you need to use abstractions.

Abstractions are also important in our daily life. It is a mechanism that allows us to get an understanding of things without knowing all the details.

If you want to read more about the topic, you can check the (amazon) link bellow. It is a book that has a whole chapter on this topic.

Related posts:

Source: An Introduction to Object-Oriented Programming, by Timothy Budd.

This post may contain affiliate links to sustain our blogging endeavours. If you use these links to buy something we may earn a commission at no extra cost for you. We only recommend what we already used ourselves and got a positive result.