The shape of the lesson
By the end of the lesson, learners can
- Why we need abstraction: A real system holds far more detail than any program can or should handle.
- 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.
- Decomposition into modules: Decomposition breaks a problem down step by step until each part is small enough to code.
- Abstraction: remove details not needed; keep only the essential ones; the result is an abstract model.
- Benefits: less complex, easier to understand, quicker to design and program, less data, reusable model.
- Decomposition: break a problem into sub-problems, again and again, until each can be solved.
- Modules: each sub-problem becomes a procedure (CALLed) or a function (returns a value, used in an expression).
One picture every idea returns to
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.
Forty-five minutes, phase by phase
| Time | Phase | What happens in the room | Grouping |
|---|---|---|---|
| 0 to 5 min | Hook: predict | Open with the question in the title, Think like a programmer.. Before any code is written, a programmer has to make a real problem small enough to solve. Put the figure on the board: it is the one picture every idea in the lesson returns to. | Whole class, then pairs |
| 5 to 13 min | Teach and check: Why we need abstraction | A real system holds far more detail than any program can or should handle. | Whole class, then pairs |
| 13 to 21 min | Teach and check: 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. Model the worked example A lift controller on the board, one line at a time. 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. | Pairs |
| 21 to 30 min | Teach and check: Decomposition into modules | Decomposition breaks a problem down step by step until each part is small enough to code. Project tab 5 of the lab (Procedures and functions as modules) and let a student drive it while the class predicts. | Connect-Extend-Challenge |
| 30 to 36 min | Check | The four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong. | Individual, then whole class |
| 36 to 43 min | Plenary | The exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording. | Individual, random call |
| 43 to 45 min | Exit and homework | Set the worksheet below (6 questions, 18 marks). Learners self-assess against the objectives before they leave. | Individual |
Protect the parts that carry the learning
The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.
Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.
Cut first if the build overruns: the last check in Decomposition into modules, never the check or the plenary.
In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.
Connect-Extend-Challenge
After the new idea, each student writes three lines: how it connects to what they knew, how it extends their thinking, and what still challenges them. Pairs compare, then the challenges become the plenary.
The full structure, with its variations and the other twelve, is on the cooperative-learning page.
What to head off, and how
| Trap learners fall into | Teaching move that pre-empts it |
|---|---|
| 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. |
| 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. |
| 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). |
Abstraction and decomposition: worksheet
6 questions, 18 marks. Written in the style of the papers; no past paper question is reproduced.
Describe the purpose of abstraction when designing a solution to a problem.
State three benefits of using abstraction.
A cinema wants a program to sell seats online. Produce an abstract model of a seat for this program by identifying three essential details. Give one detail that should be left out and justify your choice.
Explain how decomposition leads to the use of procedures and functions in a program.
A team is writing a payroll program. Give three advantages of decomposing the program into modules.
Write pseudocode for a function Larger that takes two integer parameters and returns the larger of the two. Then write a statement that uses the function to output the larger of Score1 and Score2.
Answer key and marking notes
- Removing / filtering out details that are not relevant to the problem.
- To produce a simplified (abstract) model that keeps only the essential details.
- The problem is less complex / easier to understand.
- The solution is quicker to design and program (less development time).
- Less data needs to be collected and stored / the program is smaller; the model may be reused (any one).
- Seat identifier, e.g. row letter and seat number.
- Whether the seat is booked or available (for the chosen showing).
- Price band / seat type (e.g. standard, premium, wheelchair space).
- Left out: e.g. colour of the seat fabric, because it does not affect booking or pricing.
- The problem is broken down into smaller sub-problems (repeatedly).
- Each sub-problem is small enough to be coded as one module: a procedure or a function.
- Modules can be written by different programmers at the same time.
- Each module can be tested on its own, so errors are easier to find and fix.
- Modules can be reused (called many times or in other programs), so code is not repeated; maintenance is easier.
- Header
FUNCTION Larger(A : INTEGER, B : INTEGER) RETURNS INTEGER. IF A > B THEN RETURN A ELSE RETURN B ENDIF(or equivalent; either value if equal).ENDFUNCTION.OUTPUT Larger(Score1, Score2)(no CALL, used in an expression).
6 multiple-choice questions on this lesson
From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.
Which statement best describes the purpose of abstraction when designing a solution?
- ATo remove details that are not needed, giving a simpler model that keeps only the essential ones
- BTo break the problem into smaller sub-problems that can each be solved separately
- CTo write the solution as a sequence of numbered steps in structured English
- DTo add more detail to each step until it can be written as program code
A program shows parents where their child's school bus is and when it will arrive at each stop. Which detail should be removed from the abstract model of the bus?
- AThe colour of the seats
- BThe current position of the bus
- CThe order of the stops on the route
- DThe average speed of the bus
Which is a benefit of decomposing a large program into modules?
- AEach module can be written and tested separately, possibly by different programmers
- BThe whole program no longer needs to be tested once the modules work
- CThe program will need fewer variables because modules cannot declare any
- DEvery module must return a value, so errors are reported automatically
What is output by this pseudocode?
FUNCTION Band(Score : INTEGER) RETURNS STRING
IF Score >= 80 THEN
RETURN "Gold"
ELSE
IF Score >= 60 THEN
RETURN "Silver"
ELSE
RETURN "Bronze"
ENDIF
ENDIF
ENDFUNCTION
OUTPUT Band(80) & "-" & Band(60) & "-" & Band(59)- A
Gold-Silver-Bronze - B
Silver-Bronze-Bronze - C
Gold-Silver-Silver - D
Silver-Silver-Bronze
A program contains these two modules:
PROCEDURE ShowTotal(Total : REAL) FUNCTION AddTax(Price : REAL) RETURNS REALWhich statement is valid 9618 pseudocode?
- A
CALL ShowTotal(AddTax(20.0)) - B
CALL AddTax(20.0) - C
Cost ← ShowTotal(20.0) - D
CALL ShowTotal ← AddTax(20.0)
The weight of a parcel is kept in the abstract model used by a courier's delivery program, but is removed from the abstract model used by a program that sends customers tracking messages. Which statement best explains this?
- AThe details kept by abstraction depend on the purpose of the program
- BThe courier's program has not been abstracted, so it keeps every detail
- CAbstraction always removes numerical data and keeps only text
- DThe tracking program has been decomposed, so it holds less data
Quiz key
Abstraction filters out unnecessary detail so that only the essential details remain in an abstract model. Breaking a problem into sub-problems is decomposition, writing numbered English steps is structured English, and adding detail level by level is stepwise refinement.
Seat colour has no effect on where the bus is or when it arrives, so abstraction removes it. The current position, the order of stops and the speed are all needed to show the bus and predict arrival times.
Modules are small, self-contained parts that can be shared out across a team and tested on their own, which makes errors easier to find. The complete program must still be tested as a whole. Modules can declare their own local variables, and only functions return a value; procedures do not.
80 >= 80 is TRUE, so Band(80) is Gold. 60 is not >= 80 but is >= 60, so Silver. 59 fails both tests, so Bronze. The three results are joined with & and hyphens: Gold-Silver-Bronze. Silver-Bronze-Bronze treats both tests as strictly greater than, Silver-Silver-Bronze makes that mistake only at 80, and Gold-Silver-Silver treats 59 as reaching the Silver boundary.
A procedure is run with CALL, and its parameter can be any REAL expression, including the value returned by the function AddTax. CALL AddTax(20.0) is wrong because a function is used inside an expression, not CALLed. Cost ← ShowTotal(20.0) is wrong because a procedure returns no value to assign. The last option mixes a CALL with an assignment, which is not valid syntax.
An abstract model keeps only what its own task needs: the courier must plan loads and charges by weight, but a tracking message does not depend on it. The courier's model is still abstracted (it would not hold the colour of the wrapping paper, for example). Abstraction is not about numbers versus text, and decomposition splits a problem into modules rather than removing data.
What to project
The student lesson embeds these tabs. Open them full screen on the projector; every slider has a drag handle on the stage.
Slides for this lesson
A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.