AQA 7517, section 4.4.1.3
Abstraction means picking out what matters for a particular purpose and ignoring the rest. The real world is messy and full of detail. Abstraction lets us build a simpler model that is easier to think about and to compute with.
Two kinds of abstraction are in the specification.
Representational abstraction
Representational abstraction is a representation arrived at by removing unnecessary detail.
The classic example is the map of the London Underground. It doesn't show the real distances or the exact curves of the tracks. It only shows the stations, the lines and how they connect, because that's all a passenger needs to plan a journey. Everything else has been abstracted away.
More examples:
- A variable name like
scorerepresents a memory location without showing the binary address. - A flowchart shows the logic of an algorithm without the code.
- A model of traffic may include cars and their speeds, but ignore their colour.
The key question is: what is the minimum detail needed to solve this problem?
| Real thing | Abstraction | Details removed |
|---|---|---|
| A town and its roads | A graph of nodes and edges | Buildings, road width, scenery |
| A student | A record with name, ID and marks | Hair colour, hobbies |
| A chess game | A board array and the piece positions | The look of the pieces |
Abstraction by generalisation or categorisation
Abstraction by generalisation (or categorisation) is grouping things by their common characteristics to arrive at a hierarchy of the type "is a kind of".
A saloon is a kind of car, and a car is a kind of vehicle. Anything true of all vehicles (such as "can move") is stated once at the top, and then applies to everything below.
This is the idea behind inheritance in object-oriented programming (see 4.1.2.3): a subclass is a kind of its superclass, and inherits its common features.
class Vehicle:
def move(self):
return "moving"
class Car(Vehicle): # a Car is a kind of Vehicle
pass
print(Car().move()) # moving: inherited from Vehicle
Why is abstraction useful?
- It reduces complexity, so a problem becomes manageable.
- It lets us focus on one level at a time.
- It makes solutions reusable, because the common pattern is captured once.
- It makes models easier to build and test.
Worked example
Task: a taxi company wants a program to calculate fares. Describe an abstraction of a journey.
A journey can be represented by just two values: distance and waiting time. Details such as the driver's name, the colour of the car, the route's scenery and the weather aren't needed to calculate the fare, so they are left out.
def fare(distance_km, wait_minutes):
return 3.00 + 1.50 * distance_km + 0.40 * wait_minutes
print(fare(8, 5)) # 17.0
That's representational abstraction. If the company has taxis, minibuses and limousines, grouping them as kinds of vehicle with shared features would be abstraction by generalisation.
Exam tip: when asked what is meant by abstraction, say it is removing unnecessary detail (or hiding complexity) so you can focus on what is needed, and give an example that fits the scenario in the question.
Check yourself
What is representational abstraction?
A representation arrived at by removing unnecessary detail, keeping only what is needed for the purpose.
What does "is a kind of" mean, and what kind of abstraction does it describe?
It describes a hierarchy where one group is a more specific type of another, such as a car being a kind of vehicle. This is abstraction by generalisation or categorisation.
Why is the London Underground map a good example of abstraction?
It removes details such as real distances and track curves, and keeps only the stations, lines and connections that passengers need.