Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

Abstraction: keep what matters

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

45 minutes

Why a map has no trees

Look at a train map. It shows stations and lines. It does not show streets, trees or shops.

The map is useful because it leaves things out. If it showed everything, you could not read it.

Programmers do the same with a problem. Abstraction means keeping the details that matter and leaving out the rest.

Key words

WordWhat it meansExample
DecompositionBreaking a big problem into smaller parts.a shop: basket, payment
Pattern recognitionFinding what repeats or looks alike.two apps need a login
AbstractionKeeping the details that matter and leaving out the rest.a train map
InputData that goes into a solution.age of a passenger
OutputData that comes out of a solution.the fare to pay
ConstantA value that never changes.the child fare
VariableA name that holds a value. The value can change.the age of a passenger
OutcomeThe result we want at the end.the passenger pays the right fare

The cells students fill in are left blank in this preview.

Keep it or drop it?

Have a go

Keep it or drop it?

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

The purpose of abstraction

Abstraction helps you focus. A real problem has hundreds of details. Most do not matter for your solution.

It also makes a solution easy to reuse. A solution that ignores small details works for many cases.

The three tasks of abstraction

TaskWhat you doBus ticket app
1 Find what you needList the information the solution must have.Age, route, number of journeys
2 Filter out the restDrop details that do not change the answer.Bus colour, bus logo
3 Hide how it works insideLet people use a part without seeing how it works.You press Buy. You do not see the payment code.

The cells students fill in are left blank in this preview.

Try it: hide the details

Code: python
price = 2.4567
print(round(price, 2))

# round() hides the maths inside. You only say what you want.
# Change 2 to 1 and run it again.

Six questions to ask

To use abstraction on a problem, answer six questions. Look at the table. It uses a bus fare calculator.

Abstraction for a bus fare calculator

QuestionAnswer for the bus fare calculator
What inputs do we need?The age of the passenger. The number of journeys.
What outputs and outcomes do we expect?The cost to pay. The outcome: the passenger pays the right amount.
What will vary?The age and the number of journeys change for each passenger.
What will stay constant?The child fare is 1.00. The adult fare is 2.00.
What are the key actions?Choose the right fare. Multiply it by the number of journeys (fare x journeys).
What repeats?The same sum for every journey and every passenger.

The cells students fill in are left blank in this preview.

The lesson goes on

8 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.