AS Level · Topic 9.1
A-Level Computer Science 9618 / Topic 9 / AS

Think like a programmer.

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.

The key idea

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.

Abstraction: a rail map keeps only what a traveller needs parkriver 1.8 km2.4 km0.9 km HillMarketBridgeDocks HillMarketBridgeDocks the real system: every detailthe abstract model distances, bends, landmarksstations, order, connections
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.

SystemEssential details keptDetails removed
Rail mapStations, order, interchangesReal distances, bends, landmarks
Flight bookingFlight number, date, seat, passenger nameAircraft paint colour, pilot's name
Racing game carSpeed, acceleration, position, fuelEvery 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.
  1. Decide what the program has to do: move the lift to the floors that people request, safely.
  2. 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.
  3. Also essential: the maximum load, and whether the load sensor shows the lift is overloaded.
  4. 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.
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.

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.

-Rank -Level -Score -Topics
Go deeper · practice
Six original Cambridge-style questions
The purpose, need and benefits of abstraction, abstract models, and decomposing a problem into procedures and functions.