Before any code is written, a programmer has to make a real problem small enough to solve. Abstraction throws away the detail that does not matter; decomposition splits what is left into pieces that each become a procedure or function.
Abstraction means removing (filtering out) details that are not needed to solve a problem, so that only the essential details remain. The result is an abstract model of the system. It reduces complexity, so the problem is easier to understand, quicker to design and program, and needs less data. Decomposition means breaking a problem into smaller sub-problems, and those into smaller ones, until each is simple enough to solve on its own. Each sub-problem becomes a program module: a procedure or a function.
Fig. 1: a rail map is an abstract model; real distances, bends and landmarks are removed because a traveller does not need them
Section 01
Why we need abstraction.
A real system holds far more detail than any program can or should handle. A rail map (Fig. 1) is drawn for one purpose, getting from station to station, so it keeps the stations, their order and where lines connect, and leaves out everything else.
Purpose: to produce a simplified model of a problem that keeps only the details relevant to solving it.
Need: real problems are too complex to solve all at once; without abstraction a program would try to model details that change nothing about the answer.
Benefits: the problem is easier to understand; the solution takes less time to design and program; the program is smaller and needs less data to be collected and stored; the developer can focus on the parts that matter; a general model can be reused for similar problems.
System
Essential details kept
Details removed
Rail map
Stations, order, interchanges
Real distances, bends, landmarks
Flight booking
Flight number, date, seat, passenger name
Aircraft paint colour, pilot's name
Racing game car
Speed, acceleration, position, fuel
Every individual engine part
Examiner trap
Saying abstraction "makes it simpler" is too vague for the mark. Say how: it removes unnecessary details and keeps only the essential ones, so the model is less complex.
Section 02
Building an abstract model.
In the exam you may be given a scenario and asked to produce an abstract model: list only the details the system needs, often as the data it must store. Ask of every detail: does the program need this to do its job?
Worked example A lift controller
A program controls a lift in a 10-storey office building. Produce an abstract model of the lift by identifying the essential details, and give two details that should be left out.
Decide what the program has to do: move the lift to the floors that people request, safely.
Essential data: the current floor (1 to 10), the direction of travel (up, down or stopped), the list of requested floors, whether the doors are open or closed.
Also essential: the maximum load, and whether the load sensor shows the lift is overloaded.
Leave out: the colour of the lift, the music played inside it, the make of the motor; none of these changes how the lift is controlled.
Answer: Current floor, direction, requested floors, door state and load; omit colour, music, manufacturer
Your turn
A school wants a program to record library loans. Give three details about a book that the program must store, and one detail it should not store.
Store e.g. ISBN (or book ID), title, whether it is on loan / due date. Leave out e.g. the colour of the cover.
Examiner trap
An abstract model depends on the purpose. The same book needs its weight in a model for a delivery company but not in a library loans system, so always justify your choices from the scenario.
Stage 1 · Learn
Check what the sim just showed you
Four quick checks. Each correct answer earns XP and records this skill on your profile.
Quick check+10 XP
What is the purpose of abstraction?
Quick check+10 XP
A sub-problem found by decomposition is coded as a module. Which two kinds of module does the syllabus name?
Quick check+10 XP
Which is a benefit of abstraction?
Quick check+10 XP
In the lab's function program, why is the function used inside an expression rather than with CALL?
Section 03
Decomposition into modules.
Decomposition breaks a problem down step by step until each part is small enough to code. Each part then becomes a module. In the lab, run the first two programs: one module is a function, used inside an expression; the other is a procedure, CALLed as a statement on its own.
A report program can be decomposed into the sub-problems input the data, work out each grade and output the report. Two of those become modules in 9618 pseudocode:
FUNCTION Grade(Mark : INTEGER) RETURNS CHAR
IF Mark >= 70 THEN
RETURN 'A'
ELSE
IF Mark >= 50 THEN
RETURN 'B'
ELSE
RETURN 'C'
ENDIF
ENDIF
ENDFUNCTION
PROCEDURE OutputLine(Name : STRING, Mark : INTEGER)
OUTPUT Name, " scored ", Mark, ", grade ", Grade(Mark)
ENDPROCEDURE
CALL OutputLine("Amina", 64)
The call outputs Amina scored 64, grade B. The function Grade returns one value and is used inside the OUTPUT expression; the procedure OutputLine is run with CALL.
Easier to solve: each module is a small, self-contained problem.
Teamwork: different programmers can write and test different modules at the same time.
Testing and maintenance: each module can be tested on its own, and an error is easier to find and fix in one module.
Reuse: a module such as Grade can be called many times, or reused in another program, instead of repeating code.
Examiner trap
Do not call a function with CALL. In 9618 pseudocode CALL is only for procedures; a function call is part of an expression, e.g. Letter ← Grade(Mark).
Stage 2 · Exam
Exam-style questions
Unlocks once the four checks above are done. Worth more XP, written to AS Paper 1 and Paper 2 standard.
Finish the four checks above to unlock the exam questions
Exam style+20 XP
A program models a football match for a betting website. Which detail is most likely to be removed by abstraction?
Exam style+20 XP
Which statement describes decomposition?
Exam style+20 XP
Which is a benefit of decomposing a program into modules?
Exam style+20 XP
Given FUNCTION Grade(Mark : INTEGER) RETURNS CHAR, which statement is valid 9618 pseudocode?
Skill unlocked
Abstraction and decomposition, mastered.
This skill is now recorded on your profile. Keep the chain going.