What is abstraction in computer science

A complex concept with a simple idea

Pedro Alvarado
5 min readMar 29, 2022
Photo by Emile Perron on Unsplash

Abstraction may sound complex and difficult, but the truth is that the only complex thing about this concept is its name. The idea behind the abstraction is very simple, and the idea of abstraction makes life easier for us as software developers. Today, I will explain you in a simple way what abstraction is.

What is abstraction

Abstraction is focusing on the relevant information, separating the relevant information from the secondary details. For example, you can use a calculator without knowing how specifically the calculator works. You can use a car without knowing how specifically the car works. You are separating the relevant information, which is to know how to drive the car or use the calculator, from the secondary details on how does they works internally. You don’t need to know assembler to code in Python, Javascript or any other language. You are focusing on the relevant information.

If two programmers are jointly hunting a bug in their code, they’re probably not discussing transistors.
— Max Tegmark, Life 3.0

The power of abstraction comes from filtering out — essentially, ignoring — the characteristics that we don’t need in order to concentrate on those that we do. If you think about it, this make us better, faster and more efficient programmers. Imagine if you had to write your code in assembler, now that’s scary, isn’t it? But you don’t, thanks to abstraction you can write your code in high-level languages that are way much faster to write code in.

What are the secondary details

How to difference between the relevant from irrelevant details? Well, it depends on the problem you are solving. That’s why abstraction is one of the cornerstones of computational thinking. We need to start thinking as computer scientist. You can train this part of your computational thinking by problem solving at CodeWars, which is a platform where programmers solve computational problems (the range of problems is very varied), and you can use the language you want to solve them.

In maths, you learn to think mathematically by solving mathematical problems. In computer science, you learn to think computationally by solving computational problems.
— Pedro Alvarado

Up to this point, I think you have understood what abstraction is. However, I would like to give another example, to make it even clearer how to differentiate between relevant and irrelevant details.

Think of a dog, this dog has blue eyes, its coat color is a combination of black and white, and its ears are triangular and erect. You maybe have a visual image of this dog, and that is due to the specific details that I gave you. If I would tell you think of an any dog, the range of possible dogs you maybe had thought of is huge. This is because you already had abstracted the idea of a dog (you focus on the general details and ignore the specific details), you know what are the relevant details that a dog must have to be a dog.

The example above is very related to Plato’s Theory Of Ideas. If you don’t know it, i recommend you to check it out because it is very much related to this example.

Abstraction in Object Oriented Programming

One of the four cornerstones of OOP is abstraction. I will show you how abstraction is used in OOP.

You may know that classes are the models on which we will build our objects. Now, we use abstraction when we separate the data of an object to generate a mold.

Let’s say that we want an object Human. We need to think about the general and specific characteristics (attributes) or actions (methods) of a human. For example, we could say all humans eat, sleep, and work. Also a human has a name and last name.

Human Class
Human Class

We see that a general Human:

  • Eat, which increase its energy reserves.
  • Sleep, which maximize its energy reserves.
  • Work, which decrease its energy reserves.
  • And also have a name and last name.

Now, let’s say we want to create a specific person which is a programmer. This programmer person will have all the attributes and methods of a general person, but also specific attributes and methods. We will do this with the help of another cornerstone of object-oriented programming, which is inheritance.

ProgrammerHuman Class
ProgrammerHuman Class

This class ProgrammerHuman have another attribute which is the number of programming languages its knows. And have another 2 methods. In the first one its present itself. The second perform the action of coding, which makes use of another methods that are defined in the Human class.

Instance of ProgrammerHuman
Instance of ProgrammerHuman

Here we create an instance of ProgrammerHuman, we can execute its method and that’s what happen.

That’s how abstraction works in OOP. We create first a class with general details and the create another class with more specific details. In the second class we do not worry about the first class because we had already built it and it works perfectly.

The essence of abstraction is preserving information that is relevant in a given context, and forgetting information that is irrelevant in that context.
John V. Guttag

Conclusion

Abstraction is a fundamental concept in computer science and computational thinking. We already had seen what it is, some examples of it and how does it works in OOP. Although, abstraction isn’t only use in OOP, the concept of abstraction is very spread among computer science and the practical application of abstraction may differ slightly. However, you already know the basic and fundamental idea of abstraction, and remember, complex ideas are build on ideas that are basic and that anyone can understand. If you understand basic and fundamental ideas you can understand complex ideas.

Thank you for read me and see you next time!

--

--