Abstraction (computer science)
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.
- In functional programming , for example, concepts of abstraction can be implemented using lambda abstraction (a function is made into a variable from a term) and higher-order functions (parameters of functions are in turn functions) .
- 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 Tier
represents 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()) {
schwein.essen(essensreste);
}
if (kuh.istHungrig()) {
kuh.essen(gras);
}
kuh.aendereOrt(scheune);
In the example above, the class is Tier
an abstraction and is used in place of actual animals. Lebewesen
, the class from which it is Tier
derived, 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:
- 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
- object oriented programing
- Abstract data type for an abstract description of data
- Algorithm for an abstract description of a computer process
- Data modeling for structuring the data regardless of the process that uses it
- Encapsulation for hiding information
- Higher order functions for an abstraction where parameters are functions or functions are provided as return values
literature
- Harold Abelson, Gerald Jay Sussman, Julie Sussman: Structure and Interpretation of Computer Programs , 2nd Edition, MIT Press, July 25, 1996, ISBN 978-0-262-01153-2 .
- Lorenza Saitta, Jean-Daniel Zucker: Abstraction in Artificial Intelligence and Complex Systems , 1st edition, Springer-Verlag, 2013, ISBN 978-1-4614-7051-9 .
- Joel Spolsky: The Law of Leaky Abstractions . In: Joel on Software . November 11, 2002. Retrieved June 24, 2014.
- Abstraction / information hiding - CS211 course, Cornell University.
- Lev Gorodinski: Abstractions . May 31, 2012. Retrieved June 24, 2014.
Web links
- SimArch Example of a layer architecture for distributed simulation systems
Individual evidence
- ^ 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)
- ↑ Guido Krüger, Heiko Hansen: Handbuch der Java-Programming , 7th edition 2011 (accessed on June 12, 2014).
- ↑ 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.
- ↑ Luciano Floridi : Levellism and the Method of Abstraction . (PDF) IEG - Research Report November 22, 2004