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
| Word | What it means |
|---|---|
| Function | A small named job in a program. |
| Unit test | A small test that checks one small part of the code. |
| Design approach | A way of planning software before and while you build it. |
| Critical thinking | Asking questions, comparing choices and giving reasons for your decision. |
| Top-down design | Start with the whole system and split it into smaller jobs. |
| Object-oriented design | Build the program from objects (things that hold data and can act). A class is the plan for making an object. |
| Data model | A picture of the data you need and how it is organised. |
| TDD | Test-driven development. Write a failing test first, then the code. |
| BDD | Behaviour-driven development. Write the wanted behaviour in plain words first. |
| Functional design | Build the program from small functions that each do one job. |
| Project method | The plan for how a whole team runs a project, such as waterfall or agile. |
| Waterfall | A project method with steps one after another: plan, design, build, test. |
| Agile | A project method that works in short steps and welcomes change. |
| Sprint | A 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
| Approach | It starts from | Good for | Example |
|---|---|---|---|
| Top-down (function-orientated) | The whole system, split into jobs | A system with many steps and data that moves | A pizza ordering system |
| Object-oriented | The things in the problem | Many similar things that share behaviour | A game with many characters |
| Data model | The data and how it links | Systems that store a lot of linked data | A school library |
| TDD | A failing unit test | Rules that must be exactly right | A fare calculator |
| BDD | A behaviour in plain words | Work with customers who are not developers | A student ticket feature |
| Functional | Small functions | Jobs that change data step by step | Sorting 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
# 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 questionsYour 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.