Abstraction (computer science)

from Wikipedia, the free encyclopedia

The term abstraction is used very often in computer science and describes the separation between concept and implementation . Structures are defined by their meaning, while the detailed information about the functionality remains hidden. Abstraction aims to ignore the details of the implementation and to derive a general scheme for solving the problem. A computer program can thus have different levels of abstraction, with a different level of information content being disclosed to the programmer on each level. A low level abstraction includes details about the hardware the program is running on. Higher abstraction levels, on the other hand, deal with the business logic of the software.

Abstraction deals with the level of detail of an object, which is needed in the context of the current perspective, and can be applied to the data as well as the control of a program:

  • The abstraction of the control includes the use of subroutines and concepts such as control flow .
  • Data abstraction allows the meaningful processing of data bits, for example as data types .

A general recommendation to use abstraction whenever it tries to avoid duplication is called the abstraction principle. The requirement for programming languages ​​to provide mechanisms for this recommendation is also called this.

Basic principle of abstraction

Abstraction makes it possible to highlight and derive the essentials from a set of individuals (things, observations ...) from a certain point of view, and is thus a central means for creating and understanding models.

It helps the programmer to reduce the complexity of a problem by ignoring details. The ability to think abstractly and to implement them is therefore one of the most important foundations for programming. The importance of abstraction cannot be overestimated.

A central form of abstraction is the abstraction of language. For example, artificial languages ​​are constructed that allow specific aspects of systems to be expressed. Modeling languages can help in the context of software system planning. Machine languages can be processed directly by computers. This abstraction process can also be observed with the generation change of the programming languages .

Even within a programming language, it is up to the programmer to create new levels of abstraction. The creation of subroutines , modules and software components are examples of this. Other forms of abstraction such as design patterns and software architectures remain hidden from the programming language and relate to the design of the system.

Abstraction tries to hide the complexity of the levels of abstraction below. Joel Spolsky has criticized precisely these efforts: "All non-trivial abstractions are leaky to some degree."

Language features

Programming languages

Different programming languages offer different possibilities of abstraction, such as:

  • In object-oriented languages such as C ++ , Object Pascal or Java , the concept of abstraction was implemented in the form of a separate declarative instruction. After such a declaration it is the task of the programmer to implement a class in order to be able to create an instance of an object from it.
  • Modern programming languages ​​within the Lisp language family , such as Clojure and Common Lisp , allow syntactic abstraction, which enables the programmer to eliminate standard formulations in the code, to implement new control structures, or even to develop domain-specific languages. These concepts enable an increase in efficiency in programming and an improvement in code understandability.

Specification languages

Specification languages ​​generally rely on different forms of abstraction, since the specification of a software project typically takes place at a very early and therefore at a much more abstract point in time in the project. The Unified Modeling Language is a specification language that allows, for example, to define abstract classes. These remain abstract throughout the entire architecture and specification phase of the project.

Data abstraction

The data abstraction ensures a clear separation of the abstract properties of a data type and the concrete implementation details. The abstract properties are the outwardly visible interfaces. Concrete implementations remain completely private and can be changed over time. Reasons for this would be, for example, improvements in efficiency. It is important that such changes do not have any external effects on the interface, as they do not affect the abstract behavior.

Abstraction in object-oriented programming

In object-oriented programming , objects represent the abstract “actors” who perform work, change their state and can communicate with other objects in the system. The detailed information about the exact condition of the object is often hidden, which is also referred to as information hiding or encapsulation . Here details are hidden so as not to make the problem too complex.

Another form of abstraction in object-oriented programming can also be found in the course of polymorphism . This diversity allows objects of different types to be exchanged with one another. The inheritance of classes and structures is also a form of abstraction that makes it possible to map a complex structure of relations.

Various object-oriented programming languages ​​offer comparable concepts for abstraction. All have the goal of supporting the diversity in object-oriented programming.

The following code example in Java shows a simple model of animals on a farm. Different levels of abstraction are introduced here. The class Tierrepresents both the state of an animal and the functionalities .

public class Tier extends Lebewesen
     private Ort ort;
     private double energieReserven;

     public boolean istHungrig() {
         return energieReserven < 2.5;
     public void essen(Futter futter) {
         // Futter essen
         energieReserven += futter.getKalorien();
     public void aendereOrt(Ort o) {
         //Tier auf anderer Stelle unterbringen
         this.ort = o;

With this definition, objects of the type Tier can be created and the following methods can be called:

schwein = new Tier();
kuh = new Tier();
if (schwein.istHungrig()) {
if (kuh.istHungrig()) {

In the example above, the class is Tieran abstraction and is used in place of actual animals. Lebewesen, the class from which it is Tierderived, is another form of abstraction. In this case it is a generalization of the class Tier.

If one would need a further differentiation of the animals at this point - for example, a differentiation between animals that deliver milk or no milk, a further level of abstraction can be included.

Levels of abstraction

Computer science very often speaks of different levels of abstraction (English levels or layers ). Each level describes a model of the same information on a different level of abstraction in the context of the respective domain.

Each more abstract, higher level is on a comparatively more concrete, lower level. For example, gates are based on electronic circuits , binary interfaces are based on gates, machine languages ​​are based on binary interfaces, programming languages ​​are based on machine languages ​​and applications, and operating systems are based on programming languages.

Database systems

With database systems, the complexity is very often reduced by dividing the application into abstraction levels:

Abstraction levels of a database system
  • Physical level : This level of abstraction describes how the data is actually stored in the system. Complex data structures are defined and described in detail here.
  • Logical level : The next higher level of abstraction describes which data is stored in the database and which relationships exist within this data. The user on the logical level does not need to have any knowledge of the physical level, even if he uses it indirectly via the logical level.
  • View level : The highest level of abstraction describes only parts of the entire database, since many users only need a certain section of the entire system and only have access to a small excerpt of the database. In this way, the system can offer different users different views .

See also


Web links

  • SimArch Example of a layer architecture for distributed simulation systems

Individual evidence

  1. ^ Martin Glinz: Computer Science II: Modeling - Abstraction . 2005. Retrieved June 14, 2014. - Slides by Martin Glinz at the University of Zurich (Institute for Computer Science)
  2. Guido Krüger, Heiko Hansen: Handbuch der Java-Programming , 7th edition 2011 (accessed on June 12, 2014).
  3. Joel Spolsky: The Law of Leaky Abstractions . 2002. Retrieved June 12, 2014. - A blog post by Spolsky claiming that all non-trivial abstractions are "leaky" and therefore problematic.
  4. Luciano Floridi : Levellism and the Method of Abstraction . (PDF) IEG - Research Report November 22, 2004