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 | Starting with the whole system, then splitting it into smaller parts. | Pizza app, then Take order |
| Function-orientated design | Another name for top-down design, which builds a system from functions. | |
| Function | A small named job in a program. 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 | Breaking a big problem into small ones you 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.
Check: top-down design
Have a go
Check: top-down design
3 questionsThe pizza app, split into jobs
flowchart TD
app[Pizza app] --> take[Take the order]
app --> price[Work out the cost]
app --> send[Send to the kitchen]
app --> receipt[Print the receipt]
take --> pick[Show the menu]
take --> check[Check the address]
price --> food[Add up the food]
price --> delivery[Add the delivery fee]
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.
A data flow diagram
flowchart LR
customer([Customer]) -->|list of items| total[1 Add up food]
menu[(Menu prices)] -->|price of each item| total
total -->|food total| fee[2 Add delivery fee]
fee -->|total to pay| receipt[3 Make receipt]
receipt -->|receipt text| customer
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.
Make a free account to save your work and track your progress.
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.
Two naming rules
Tip
Name each process with a verb: Add, Check, Send. Name each arrow with a noun: order, total, receipt. If an arrow has no name, you do not yet know what data moves.
Match the DFD part
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Draw a DFD for a canteen
A school canteen has a card system. A student taps a card. The system finds the money on the card, takes off the price of lunch and shows the new balance. Finish the data flow diagram. Add a process for each job. Add a data store for the card balances. Name every arrow with a noun.
flowchart LR
student([Student]) -->|card number| find[1 Find the balance]
%% Add a data store for the balances.
%% Add a process that takes off the price.
%% Add a process that shows the new balance.
%% Send the new balance back to the student.
Make a free account to save your work, or press Start lab to work through the whole lesson.
Code the three pizza functions
Build the three functions from the data flow diagram. Food goes in and a total comes out. The total goes into the delivery job. Both numbers go into the receipt job. Press Run Tests.
MENU = {"pizza": 8, "chips": 3, "drink": 2}
def order_total(items):
# items is a list of names, like ["pizza", "chips"].
# Give back the cost of the whole food order in pounds.
return None
def delivery_fee(total):
# An order of 20 pounds or more has free delivery.
# Under 20 pounds, delivery costs 3 pounds.
return None
def receipt_line(total, fee):
# Give back text like: Food 19, delivery 3, pay 22
return None
Make a free account to save your work, or press Start lab to work through the whole lesson.
Key words crossword
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Exit quiz
Have a go