One pizza order, many jobs
You order a pizza on your phone. Many things happen before it arrives.
Someone checks the menu. Someone adds up the cost. Someone tells the kitchen. Someone prints the receipt.
A big system is not one big job. It is many small jobs. Today you learn how to plan them.
Key words
| Word | What it means | Example |
|---|---|---|
| Top-down design | Start with the whole system. Then split it into smaller parts. | Pizza app, then Take order |
| Function-orientated design | Another name for top-down design. The system is built from functions. | |
| Function | A small job in a program with a name. It takes data in and gives data out. | order_total() |
| Sub-system | A smaller part of a bigger system. | The kitchen screen |
| Divide and conquer | Break a big problem into small problems you can solve one by one. | |
| Data flow | The way data moves from one part to the next. | |
| Data flow diagram | A picture that shows each job and the data that moves between them. | DFD |
The cells students fill in are left blank in this preview.
Start at the top
In top-down design you start with one big box: the whole system.
Then you ask: what jobs must it do? Each job becomes a smaller box. Then you split those boxes again. You stop when each box is one simple job.
Each simple job becomes one function in the code.
Quick check: top-down
Have a go
Quick check: top-down
3 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.
Follow the data
A system is not only a list of jobs. Data moves between the jobs.
The order goes from the customer to the cost job. The cost goes to the receipt job. This movement is the data flow.
A data flow diagram (DFD) draws the jobs as boxes and the data as labelled arrows.
Try it: data flows through functions
def add_up(prices):
return sum(prices)
def add_fee(total):
return total + 3
prices = [8, 3, 2]
food = add_up(prices)
pay = add_fee(food)
print("Food", food)
print("Pay", pay)
# Each function is one box. The variables are the arrows.
# Change the prices and run again.
The four parts of a DFD
| Part | What it is | Example |
|---|---|---|
| External entity | A person or system outside your system | Customer |
| Process | A job that changes data. Name it with a verb | Add up food |
| Data store | Where data waits until it is needed | Menu prices |
| Data flow | An arrow that carries data. Name it with a noun | food total |
The cells students fill in are left blank in this preview.