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

Preview

Choosing a design approach

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

40 minutes

Four problems, one choice

Problem 1: a pizza app with many steps. Problem 2: a game with 100 zombies. Problem 3: a library that must remember who has which book. Problem 4: a payment rule that must never be wrong.

Does one design method fit all four? No. A good developer thinks first and then chooses. This is called critical thinking.

Key words

WordWhat it means
FunctionA small named job in a program.
Unit testA small test that checks one small part of the code.
Design approachA way of planning software before and while you build it.
Critical thinkingAsking questions, comparing choices and giving reasons for your decision.
Top-down designStart with the whole system and split it into smaller jobs.
Object-oriented designBuild the program from objects (things that hold data and can act). A class is the plan for making an object.
Data modelA picture of the data you need and how it is organised.
TDDTest-driven development. Write a failing test first, then the code.
BDDBehaviour-driven development. Write the wanted behaviour in plain words first.
Functional designBuild the program from small functions that each do one job.
Project methodThe plan for how a whole team runs a project, such as waterfall or agile.
WaterfallA project method with steps one after another: plan, design, build, test.
AgileA project method that works in short steps and welcomes change.
SprintA short, fixed time, often two weeks, in which an agile team finishes some work.

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

Six approaches at a glance

ApproachIt starts fromGood forExample
Top-down (function-orientated)The whole system, split into jobsA system with many steps and data that movesA pizza ordering system
Object-orientedThe things in the problemMany similar things that share behaviourA game with many characters
Data modelThe data and how it linksSystems that store a lot of linked dataA school library
TDDA failing unit testRules that must be exactly rightA fare calculator
BDDA behaviour in plain wordsWork with customers who are not developersA student ticket feature
FunctionalSmall functionsJobs that change data step by stepSorting and filtering a list

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

Approaches work together

The approaches do not compete. One project often uses several.

A game team may plan the whole game top-down. They use classes for the characters. They draw a data model for scores and players. They write tests first for the scoring rules.

You choose by asking questions about the problem.

Try it: three ideas in one program

Code: python
# A data model: a dictionary of prices
MENU = {"pizza": 8, "chips": 3}


# Function-orientated design: one small job
def total(items):
    cost = 0
    for item in items:
        cost = cost + MENU[item]
    return cost


# Object-oriented design: a class
class Order:
    def __init__(self, items):
        self.items = items

    def cost(self):
        return total(self.items)


# Test-driven: the test says what we want
def test_cost():
    assert Order(["pizza", "chips"]).cost() == 11


test_cost()
print("The test passes")

Which approach fits?

Have a go

Which approach fits?

5 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.

Design inside a project method

Every team also has a project method. It decides when design happens.

In waterfall, you design once, before you build. A wrong choice costs a lot later.

In agile, you design a little in every sprint. TDD and BDD fit well, because tests and behaviours are small and can change.

The lesson goes on

4 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.