A UML class diagram is a standardised blueprint that shows the attributes, methods, and relationships of the classes in an object-oriented program. At GCSE, class diagrams help you plan OOP designs on paper before writing code and frequently appear in exam questions on inheritance, encapsulation, and class hierarchies.
What is UML and why do we use class diagrams?
UML stands for Unified Modelling Language — a family of diagramming notations used by software engineers to plan and document programs. Class diagrams are the most common UML diagram type and are particularly useful for object-oriented design because they capture the structure of a system without committing to any particular programming language.
A class diagram lets you see, at a glance, what data each class stores, what operations it can perform, and how classes relate to one another. Spotting a missing attribute in a class diagram costs nothing; discovering the same gap after writing thousands of lines of code costs hours.
At GCSE, you are expected to understand the notation of class diagrams when reading exam questions, and some specifications require you to draw simple class diagrams as part of your programming project documentation.
What does a class box look like?
Each class is represented by a rectangle divided into three horizontal sections:
┌──────────────────────┐
│ ClassName │ ← 1. Class name (centred, often bold)
├──────────────────────┤
│ - attribute1: Type │ ← 2. Attributes (instance variables)
│ # attribute2: Type │
├──────────────────────┤
│ + method1(): Type │ ← 3. Methods (operations)
│ + method2(p: Type) │
└──────────────────────┘
The visibility symbols before each name indicate access level:
| Symbol | Visibility | Meaning |
|---|---|---|
+ |
Public | Accessible from any class |
- |
Private | Accessible only within this class |
# |
Protected | Accessible within this class and its subclasses |
A worked example: the Animal class
Consider a simple class representing an animal in a program:
┌─────────────────────────┐
│ Animal │
├─────────────────────────┤
│ - name: String │
│ - age: Integer │
├─────────────────────────┤
│ + getName(): String │
│ + getAge(): Integer │
│ + makeSound(): String │
└─────────────────────────┘
This tells us:
- The class is called Animal.
- It has two private attributes:
name(a String) andage(an Integer). Being private, they cannot be accessed directly from outside — only through the public methods (encapsulation). - It has three public methods:
getName()andgetAge()return values;makeSound()returns a String but its behaviour depends on the specific animal.
How is inheritance shown in a class diagram?
Inheritance is shown by a solid line with an open (hollow) arrowhead pointing from the subclass to the parent class. The arrowhead points upward towards the parent, indicating "is a".
A class hierarchy for animals might look like:
Animal
▲
┌──────┴──────┐
Dog Cat
Both Dog and Cat inherit all the attributes and methods of Animal. You only show in the Dog and Cat boxes what is additional or overridden — attributes and methods they inherit do not need to be repeated.
What other relationship arrows appear in GCSE class diagrams?
| Relationship | Arrow style | Meaning | Example |
|---|---|---|---|
| Inheritance | Solid line, open arrowhead | "Is a" | Dog is an Animal |
| Association | Plain solid line | "Uses" or "has a" | Order uses Customer |
| Aggregation | Line with open diamond | "Has a" (part can exist alone) | Team has Players |
| Composition | Line with filled diamond | "Has a" (part cannot exist alone) | House has Rooms |
| Dependency | Dashed line, open arrow | "Depends on" | Report depends on Database |
At GCSE, the most important relationships are inheritance (often the focus of exam questions) and basic association. You are unlikely to be tested on the finer distinction between aggregation and composition.
How do you use a class diagram to write Python code?
A class diagram translates directly into Python:
class Animal:
def __init__(self, name, age):
self.__name = name # private: -- prefix
self.__age = age
def get_name(self):
return self.__name
def get_age(self):
return self.__age
def make_sound(self):
return ""
class Dog(Animal): # Dog inherits from Animal
def make_sound(self):
return "Woof!"
The class box maps directly: attributes become __init__ parameters, private attributes get double-underscore prefixes in Python, and the inheritance arrow becomes class Dog(Animal):.
Frequently asked questions
Do I have to draw UML class diagrams in my GCSE project?
This depends on your specification. AQA GCSE Computer Science does not mandate UML, but encourages design documentation that shows the structure of your program. OCR likewise values design evidence. Using a simple class diagram (even a hand-drawn one) as part of your design section demonstrates structured planning and can earn design marks. Check your specification and centre guidance.
What is the difference between a class diagram and an object diagram?
A class diagram shows the template — the structure that all objects of a class share. An object diagram shows a specific instance at a particular moment in time: one Dog object called "Rex" with age 3. Class diagrams are the norm in GCSE; object diagrams are more common at A-level.
What does it mean when a method has no return type listed?
In some notations, a method with no return type indicator either returns void (nothing) or the return type has been omitted for brevity. In Python terms, it would be a procedure (a function that performs an action but returns None). When drawing your own diagrams, including the return type is good practice even if the exam mark scheme does not penalise its absence.
Can a class diagram show abstract methods or abstract classes?
Yes. In UML, abstract class names and abstract method names are written in italics. Abstract classes cannot be instantiated; they provide a common interface that concrete subclasses must implement. At GCSE, the concept of abstraction in OOP is assessed — being able to label an abstract class correctly in a diagram demonstrates that understanding.
Get step-by-step OOP design help from Professor Turing at aitutors.me, covering class diagrams through to working Python code.