Skip to content

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 abstractionWith abstraction
Overwhelming amounts of irrelevant detailOnly relevant information present
Hard to see the structure of the problemClear, simple model to work from
Slow to design and buildFaster to develop and test
Difficult to communicate to othersEasy 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 encoding

Most 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:

DecompositionAbstraction
What it doesBreaks problem into partsRemoves irrelevant detail
FocusStructure and sizeSimplification
ResultSub-problemsA simplified model
AnalogyCutting a cake into slicesTaking 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.63

The caller only sees calculate_interest(1000, 0.05, 3) - the formula is hidden. This is procedural abstraction.


Summary

TermMeaning
AbstractionRemoving irrelevant detail to simplify a problem
Abstracted modelA simplified representation of reality
Procedural abstractionHiding how a function works; the caller only needs to know what it does
Level of abstractionHow much detail has been removed - higher = less detail

Test Yourself

Question 1 of 5

Which of the following best describes abstraction in computational thinking?

Ad

PassMaven - revision made simple.