Grade by Grade
B. Software Development · Software Development: Problem Solving, Design, Testing and the Life Cycle

Structure Charts, Data Flow Diagrams and UML

B2.4 B2.2 B2.3About 70 minutes
Learning goals
  • I can draw a structure chart that shows a program's modules, who calls whom, and the data passed between them.
  • I can read and draw a simple data flow diagram with external entities, processes, data stores and data flows.
  • I can read and draw a UML class diagram with a name, attributes and methods.
  • I can choose the right diagram for what I need to explain.

Words to know

module
A self-contained part of a program that does one job, such as a function. Modules are the building blocks in a structure chart.
structure chart
A top-down diagram of a program's modules. Lines show which module calls which; small arrows (data couples) show the data passed.
data couple
A small arrow with an open circle on a structure chart, showing data passed into or out of a module.
data flow diagram (DFD)
A diagram of how data moves through a system: between external entities, processes and data stores. It does not show order or decisions.
data store
A place where data is kept for later, such as a file or database. Drawn as an open-ended rectangle in a DFD.
UML
Unified Modeling Language: a standard set of diagrams for designing software. The class diagram is the most common.
class diagram
A UML box with three parts: the class name, its attributes (data) and its methods (actions).

Zooming out

A flow chart shows the steps inside one algorithm. But a real program has many parts. A video game has a part for drawing the screen, a part for reading the controller, a part for scoring, and so on. To plan and explain a whole program, you need diagrams that show the big picture:

  • A structure chart shows how a program is split into modules and which module calls which.
  • A data flow diagram shows how data moves through a system.
  • A UML class diagram shows the data and actions that belong together in a class.

All three are used in industry, and all three are named in the Ontario curriculum.

Structure charts

A structure chart looks like an organization chart. The main module is at the top. Below it are the modules it calls. Each box is usually one function.

  • A line from a higher box to a lower box means the higher module calls the lower one.
  • A small arrow with an open circle is a data couple: data passed down (as an argument) or up (as a return value).
  • Modules are usually called left to right, but a structure chart does not show loops and decisions in detail. That is the job of a flow chart or pseudocode.

Structure charts come straight from stepwise refinement: each refinement level becomes a row of boxes.

mainload_questions()ask()show_score()questions, answersquestion, answercorrect (True/False)score, totalLines show who calls whom. Small arrows with open circlesare data couples: the data passed between modules.
Structure chart for a quiz program. main calls three modules. The data couples show what each module receives and sends back: ask() receives one question and its answer and returns whether the reply was correct.
Worked example

Example 1: From structure chart to code

Write a Python quiz program that follows the structure chart. (To keep it short, load_questions returns two questions.)

  1. Each box becomes a function. The data couples going down become parameters; the data couples going up become return values.
  2. load_questions() returns two lists: the questions and the answers.
  3. ask(question, answer) returns True or False.
  4. show_score(score, total) prints the result; it returns nothing.
  5. main() calls them in order, left to right, and keeps the score.

The program below matches the chart box for box. With the replies Ottawa and 5, it prints You scored 1/2.

def load_questions():
questions = ["Capital of Canada?", "2 + 2 ="]
answers = ["ottawa", "4"]
return questions, answers
def ask(question, answer):
reply = input(question + " ")
return reply.strip().lower() == answer
def show_score(score, total):
print(f"You scored {score}/{total}")
def main():
questions, answers = load_questions()
score = 0
for i in range(len(questions)):
if ask(questions[i], answers[i]):
score = score + 1
show_score(score, len(questions))
main()

Sample run: the user answers Ottawa (correct, because .lower() makes it match "ottawa") and 5 (wrong). Output: You scored 1/2. return questions, answers sends back two values at once.

Data flow diagrams (DFDs)

A DFD ignores the order of steps. It answers one question: where does the data come from, where does it go, and what changes it? It uses four symbols:

  • External entity (rectangle): a person or system outside the program that sends or receives data, such as a student or a bank.
  • Process (circle or rounded box, numbered): something that changes data, such as "Check out book".
  • Data store (open-ended rectangle): where data is kept, such as a file or database.
  • Data flow (labelled arrow): the data moving. Every arrow is labelled with a noun (the data), not a verb.
Student1Check outbookD1BooksD2Loansstudent ID, book IDreceipt withdue datebook detailsnew loan record
A data flow diagram for checking out a library book. The student sends IDs to process 1, which reads book details from the Books store, writes a new record to the Loans store, and sends a receipt back.
Worked example

Example 2: Reading a DFD

Using the library DFD, answer: (a) Which data does process 1 read but not change? (b) Which data store is written to? (c) Why is there no arrow straight from Student to the Loans store?

  1. (a) Process 1 reads book details from D1 Books. The arrow points out of the store, so data is read.
  2. (b) D2 Loans: the arrow labelled new loan record points into it.
  3. (c) In a DFD, data can only enter or leave a store through a process. An outside person cannot write straight into the database; the program checks and records the loan.

(a) book details; (b) D2 Loans; (c) external entities never connect directly to data stores.

UML class diagrams

UML (Unified Modeling Language) is a family of standard diagrams. The most common is the class diagram. A class bundles data (attributes) together with the actions (methods) that use that data. It is one of the main tools for modularity and reuse: once a Student class is written, any program can use it.

A class diagram is a box with three compartments:

  1. the class name,
  2. the attributes, written name: type,
  3. the methods, written name(parameters): return type.

A + means public (other code may use it); a - means private (only the class itself should use it).

Student- name: str- marks: list+ add_mark(mark: int)+ average(): floatclass nameattributes (data)methods (actions)- private+ public
UML class diagram for a Student class: the name on top, attributes in the middle, methods at the bottom. The symbols + and − show which parts are public and private.
Worked example

Example 3: From UML to Python

Write the Student class from the diagram, then create a student named Maya with marks 80 and 90 and print her average.

  1. The class name becomes class Student:.
  2. Attributes are set up in the special method __init__, which runs when a new object is created. self means "this particular student".
  3. Each method becomes a def inside the class, with self as its first parameter.
  4. Create an object (one student) with Student("Maya"), then call its methods with a dot.

The program prints Maya 85.0. You will not need to write classes in this course's tests, but you should be able to read a class diagram and recognize classes as reusable modules.

class Student:
def __init__(self, name):
self.name = name
self.marks = []
def add_mark(self, mark):
self.marks.append(mark)
def average(self):
return sum(self.marks) / len(self.marks)
s = Student("Maya")
s.add_mark(80)
s.add_mark(90)
print(s.name, s.average())

Output: Maya 85.0

DiagramShowsBest for
Flow chart / pseudocodesteps, decisions and loops inside one algorithmdetailed logic
Structure chartmodules, who calls whom, data passedplanning functions and splitting team work
Data flow diagramwhere data comes from, goes and is storedexplaining a system to users and clients
UML class diagramdata and methods grouped into classesobject-oriented design and reuse
Choosing a design diagram.
Just for fun

UML was created in the mid-1990s by three software designers, Grady Booch, Ivar Jacobson and James Rumbaugh. Programmers nicknamed them "the Three Amigos".

Hands-on activity

Diagram your kitchen

You need: paper and a pencil.

  1. Structure chart: plan a program called make_breakfast. Break it into 3 or 4 modules (for example choose_menu, cook_eggs, make_toast, serve). Add at least two data couples (what is passed between modules, such as number_of_people).
  2. DFD: draw how data moves when a family member orders a pizza online: entities (customer, pizza shop), processes (place order, take payment), stores (menu, orders), labelled flows.
  3. UML: draw a class diagram for a Recipe class with at least two attributes (such as name, servings) and two methods (such as scale(people), print_card()).
  4. Explain one diagram to someone at home in under a minute.

What to look for: correct symbols, every DFD arrow labelled with a noun, no arrow from an entity straight to a data store, and three compartments in the UML box.

Your turn

1

In a structure chart, what does a line from box A down to box B mean?

2

In the quiz structure chart, which data couple goes up from ask() to main? What is its type?

3

Name the four symbols of a data flow diagram.

4

What are the three compartments of a UML class box?

5

In UML, what do + and - mean in front of an attribute or method?

6

Which diagram would you use to show which functions a program has and how they call each other?

7

A DFD has an arrow labelled "check" going into a data store. What is wrong with the label?

More practice: warm-up

1

What does UML stand for?

2

What symbol represents a data store in a DFD?

3

Which module is at the top of a structure chart?

4

Does a DFD show the order in which things happen?

5

In the Student class, what does average() return for marks 70, 80 and 90?

More practice: on your own

1

Draw (or describe) a structure chart for a program that reads three test marks, calculates the average and prints a letter grade. Include data couples.

2

For a school cafeteria payment system, name one external entity, one process, one data store and one data flow.

3

Write a UML class box (in text) for a Team class with a name, a list of players, a method to add a player and a method that returns how many players there are.

4

Explain how a structure chart helps a team of programmers split up the work.

5

Using the Student class from the lesson, what does this print? t = Student("Liam"), t.add_mark(64), t.add_mark(71), t.add_mark(90), print(t.average())

Challenge

1

A student's structure chart has calc_tax() calling main(). Explain what is wrong and what problem it could cause in code.

2

Draw (or describe) a level-0 DFD for an online snow-day alert system: the school board enters closures, parents subscribe with an email address, and the system emails alerts.

3

Why is a class a good example of the principle of modularity? Give one way the Student class could be reused.

Check your understanding

Quiz

1.

What does a structure chart mainly show?

2.

In a DFD, which symbol is a data store?

3.

In a UML class diagram, where are the methods listed?

4.

In a structure chart, a data couple going up from a module usually becomes what in Python?

5.

Which statement about DFDs is true?

6.

In UML, - balance: float means:

For parents and teachers

Big idea: B2.4 names structure charts, data flow diagrams and UML as industry-standard design tools; B2.2 asks students to explain a program's structure with diagrams; B2.3 (modularity and reuse) is the reason these diagrams matter: they show how a program is split into reusable parts.

How to help: Ask your teen to explain one diagram from their notes to you in a minute. If they can explain it, they understand it. The kitchen activity works well as a family conversation.

Common difficulties:

  • Mixing up diagrams: putting decisions in a structure chart or a DFD, or putting verbs on DFD arrows.
  • Drawing an arrow straight from a person to a data store in a DFD.
  • Forgetting the data couples, which are what make a structure chart useful for teamwork.
  • Classes may feel new. In this course it is enough to read a class diagram and see a class as one reusable module.