← VCE Software Development U3O1

Designing classes with a class diagram

A box listing a class's name, attributes and methods. An arrow joins a child class to the parent it inherits from. You draw it as a plan before writing the code.

Understanding Designing classes with a class diagram in VCE Software Development U3O1

What it does: The name at the top of the diagram box becomes the class name in the code, written after the keyword class. The top part of the box holds the class name. Attributes go in the middle and methods go in the bottom. Names followed by brackets are methods. They show what an object can do, so they go in the bottom section. The arrow points up to the parent. For example, Cat points to Animal because Cat inherits from Animal.

Common mistakes: The diagram lists name as an attribute of Dog. Writing name = name only makes a local variable, so the object never keeps it. It should be self.name = name. Every method in a class needs self as its first parameter so it can reach the object's attributes. It should be def __init__(self, name):.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 10–47) and word search (Modules 10–71).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
A class diagram box is split into three parts. What goes in the TOP part?
The methods, e.g. bark()The class name, e.g. Dog
Matches
Diagram box for Dog lists: Dog, speak(), name, age (methods before attributes)
↓
The box is in the wrong order. A class diagram lists the class name first, then the attributes, then the methods.
Applying
Meanings
Term
class diagram
Meaning
A box listing a class's name, attributes and methods. An arrow joins a child class to the parent it inherits from. You draw it as a plan before writing the code.
Practice
class Pet:
Testing
Gaps
Dog:
Check Answer
Spots
2 def __init__(self, name):
3 name = name

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Reindeer' badge — Dictionary Guide, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. A class diagram box is split into three parts. What goes in the TOP part?
A. The methods, e.g. bark()
B. The class name, e.g. Dog ✓
The top part of the box holds the class name. Attributes go in the middle and methods go in the bottom.
2. Which part of a class diagram lists the data an object stores, like name and age?
A. The attributes section (middle) ✓
B. The methods section (bottom)
Attributes are the data an object keeps. They sit in the middle of the box. Methods are the actions and sit at the bottom.
3. A class diagram for Student lists 'study()' and 'get_grade()'. What are these?
A. Attributes, because they store data about the student
B. Methods, because they are actions the class can do ✓
Names followed by brackets are methods. They show what an object can do, so they go in the bottom section.
4. In a class diagram, which way does the inheritance arrow point?
A. From the child class to the parent class ✓
B. From the parent class to the child class
The arrow points up to the parent. For example, Cat points to Animal because Cat inherits from Animal.
5. A diagram shows an arrow from Car to Vehicle. Which code matches it?
A. class Car(Vehicle): ✓
B. class Vehicle(Car):
The child class goes first and the parent goes in brackets. Car inherits from Vehicle, so we write class Car(Vehicle).

Match the Pairs

Dog - name - age + speak() → A class diagram box for Dog: the class name on top, then its attributes (name, age), then its methods (speak)
Puppy ──▷ Dog → An inheritance arrow showing that Puppy is a child class that inherits from the parent class Dog
Turning a diagram box into code: the class name from the box becomes the class header → class Dog:
Turning an inheritance arrow from Puppy to Dog into code: the parent class goes in brackets → class Puppy(Dog):
Diagram box for Dog lists: Dog, speak(), name, age (methods before attributes) → The box is in the wrong order. A class diagram lists the class name first, then the attributes, then the methods.
Dog ──▷ Puppy (but the code says class Puppy(Dog):) → The arrow points the wrong way. It should go from the child class Puppy to the parent class Dog.

Key Term

class diagram
A box listing a class's name, attributes and methods. An arrow joins a child class to the parent it inherits from. You draw it as a plan before writing the code.

Fill in the Blanks

1. # Diagram box: Dog class Dog: pass
Hint: Type the keyword that turns a diagram box into Python code.
2. # Arrow: Dog points to Animal class Dog(Animal): pass
Hint: Type the parent class that the arrow points to.
3. # Pet box has the attribute name class Pet: def __init__(self, name):
Hint: Type the special method name that sets up a class's attributes.
4. # Pet box - method: speak() class Pet: def speak(self):
Hint: Type the method name listed in the methods part of the diagram box.
5. # Arrow: Puppy points to Dog class Puppy(Dog): pass
Hint: Type the child class name, the class the arrow starts from.

Spot the Error

Question 1
A class Dog:
B def __init__(self, name):
C name = name
D def bark(self):
E print("Woof")
Line C — The diagram lists name as an attribute of Dog. Writing name = name only makes a local variable, so the object never keeps it. It should be self.name = name.
Question 2
A class Pet:
B def __init__(name):
C self.name = name
Line B — Every method in a class needs self as its first parameter so it can reach the object's attributes. It should be def __init__(self, name):.
Question 3
A class Animal:
B speak(self):
C print("...")
Line B — The speak method from the diagram must be defined with the def keyword. It should be def speak(self):.
Question 4
A class Animal: pass
B class Dog -> Animal:
C def bark(self):
D print("Woof")
Line B — The diagram's inheritance arrow becomes the parent class name in brackets after the child class name. It should be class Dog(Animal):.
Question 5
A class Student:
B def __init__(self, name):
C self.name = name
D def greet(self)
E print("Hi " + self.name)
Line D — The greet method from the diagram is missing the colon at the end of its def line. Python needs the colon to start the method body. It should be def greet(self):.

Student with a class code? Join your class →