Appearance
A3 · Abstraction
Spec reference: Section A - Computational Thinking
Key idea: Remove unnecessary detail. Focus on what matters for the problem.
Abstraction in Computer Science
Why abstraction is important
| Without abstraction | With abstraction |
|---|---|
| Overwhelming amounts of irrelevant detail | Only relevant information present |
| Hard to see the structure of the problem | Clear, simple model to work from |
| Slow to design and build | Faster to develop and test |
| Difficult to communicate to others | Easy to explain and document |
Levels of abstraction
Abstraction works at different levels. The higher the level, the less detail:
High-level abstraction → "Send the customer an email"
↓
Mid-level abstraction → call sendEmail(address, subject, body)
↓
Low-level abstraction → construct SMTP packet, connect to mail server,
transmit data, handle response codes
↓
Hardware level → electrical signals, voltage levels, binary encodingMost programmers work at the mid-level - using high-level languages that abstract away hardware details.
Abstraction in problem solving
When you abstract a real-world problem, you ask:
"What details are essential to solve this problem? What can I safely ignore?"
Example: Train route finder
Real world: trains have drivers, carriages, fuel levels, seat fabrics, catering menus, brake temperatures…
For a route finder, none of that matters. The abstracted model only needs:
- Station names
- Connections between stations
- Journey times (or distances)
[Station A] --25 min-- [Station B] --40 min-- [Station C]
|
30 min
|
[Station D]That simple graph is a complete abstraction for solving the routing problem.
Abstraction vs decomposition
These two are related but distinct:
| Decomposition | Abstraction | |
|---|---|---|
| What it does | Breaks problem into parts | Removes irrelevant detail |
| Focus | Structure and size | Simplification |
| Result | Sub-problems | A simplified model |
| Analogy | Cutting a cake into slices | Taking a photo that only shows the subject, not the background clutter |
Abstraction in code
In programming, abstraction means writing code so that users of a function or class do not need to know how it works, only what it does.
python
# The user of this function doesn't need to know
# how the interest is calculated - that detail is abstracted away
def calculate_interest(principal, rate, years):
return principal * (1 + rate) ** years
result = calculate_interest(1000, 0.05, 3)
print(result) # 1157.63The caller only sees calculate_interest(1000, 0.05, 3) - the formula is hidden. This is procedural abstraction.
Summary
| Term | Meaning |
|---|---|
| Abstraction | Removing irrelevant detail to simplify a problem |
| Abstracted model | A simplified representation of reality |
| Procedural abstraction | Hiding how a function works; the caller only needs to know what it does |
| Level of abstraction | How much detail has been removed - higher = less detail |
Test Yourself
Question 1 of 5
Which of the following best describes abstraction in computational thinking?