Object Oriented Programming - Abstraction

From SwinBrain

Abstraction = hiding details to focus on fewer concepts

"Abstraction is the practice of hiding away details, allowing us to concentrate on only a few concepts at a time" [1] or abstraction is "The principle of ignoring those aspects of a subject that are not relevant to the current purpose in order to concentrate more fully on those that are" [2]. As a result, abstraction is a key concept of all software development. Consider all of the details that are hidden away by programming languages. For example, the computer is an electronic machine, on top of this we build an abstraction for binary numbers, on top of which we build abstractions for data types and operations. From here the procedural paradigm focused on procedural abstractions, specifically functions and procedures and control structures.

Abstraction relates more directly to object oriented programming through the processes of classification, specialisation, and generalisation [3]: all forms of abstraction.


Abstraction is one of the four key principles of object oriented programming.
The idea of classification is to organise things into groups or families based on common attributes. These groups or families are typically called classes, and provided the inspiration for the class code structure in object oriented programming languages. In essence, a class in an object oriented context is the specification of the common features found in this 'group' or 'family' of objects. The method for designing object oriented programs is therefore to come up with classification abstractions for the concepts related to the program and implement these in a programming language as classes (see Objects and Classes).

Specialisation and Generalisation

The process of classification results in a set of classes that can be used to conceptualise the program being modelled. These classes may be sufficient, but where necessary additional classes can be discovered through specialisation and generalisation.

The process of specialisation takes an existing class from which more detailed sub classes can be created. For example, a computer game may contain a number of different weapons which, through classification, has lead to a Weapon class. Within this class we may identify several specialised weapons, leading us to Weapon sub classes like Sword, Rifle, Laser, etc. Each of these new classes is a kind of weapon, one with certain specialised features.

Generalisation take the classification hierarchy in the opposite direction to specialisation, creating more general classes. Generalisation works by identifying common features of existing classifications. In our game example we may have identified Weapon, Armour, Creature, Map, and other classifications, all with the common requirement that they can be drawn. From these classes we may choose to infer a more general Game Object class.

Specialisation and Generalisation are realised in object oriented programming languages using Inheritance.

  1. Wikipedia Abstraction (computer science)
  2. Dictionary of Computing, Oxford University Press
  3. Henderson-Sellers and Julian Edwards, Book Two of Object Oriented Knowledge: The Working Object, Prentice Hall, 1994.