SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
CAIE 9618 · Paper 4 · Topic 4.2.1

UML &
Class Design

Class Diagrams · Attributes · Methods · Relationships · Multiplicity · Association vs Inheritance

CSZone Cambridge International AS & A Level Computer Science 9618
UML Class Diagram Structure

Three-Section Box Format

ClassName
- attributeName : DataType
- anotherAttr : DataType
+ MethodName(param:Type) : ReturnType
+ AnotherMethod() : VOID
- = private, + = public
BankAccount
- AccountNumber : STRING
- Balance : REAL
+ NEW(AccNo:STRING, Bal:REAL)
+ GetBalance() : REAL
+ Deposit(Amount:REAL) : VOID
+ Withdraw(Amount:REAL) : BOOLEAN
THREE SECTIONS
Section 1 (top) — class name, bold or underlined
Section 2 (middle) — attributes with visibility (+/-), name, and data type
Section 3 (bottom) — methods/operations with visibility, parameters, and return type
VISIBILITY SYMBOLS
SymbolMeaning
+Public
-Private
#Protected (accessible by subclasses)
Relationships in UML

How Classes Relate to Each Other

RelationshipUML NotationMeaningExample
InheritanceHollow triangle arrowhead (→ superclass)IS-A: subclass extends superclassCar IS-A Vehicle
AssociationSolid line with optional arrowheadHAS-A relationship; one class uses anotherStudent takes Exam
AggregationHollow diamond at the whole endWhole-part; part can exist without wholeLibrary HAS Books (book exists without library)
CompositionFilled diamond at the whole endStronger whole-part; part cannot exist without wholeHouse HAS Rooms (room cannot exist without house)
MULTIPLICITY (cardinality)
1
Exactly one
0..1
Zero or one
1..*
One or more
0..*
Zero or more
Example: Student (0..*) ——— (1) Tutor means each student has exactly 1 tutor; a tutor has 0 or more students.
Exam Practice

Cambridge-style questions

Question 1
A school system has classes Teacher and Department. Each department is managed by exactly one teacher, and each teacher can manage zero or one departments. Draw a UML class diagram showing the Teacher class (with attributes: Name:STRING, StaffID:STRING and method GetName():STRING) and the relationship between Teacher and Department with multiplicity labels. [4]
1
Teacher class box with three sections: class name, attributes (- Name : STRING, - StaffID : STRING), methods (+ GetName() : STRING).
1
Department class box shown (can be empty or with at least class name).
1
Association line (solid) connecting Teacher and Department.
1
Correct multiplicity: Teacher side: 0..1 (a department has zero or one teacher managing it); Department side: 1 (each teacher manages exactly one department) — OR the reverse depending on how the relationship direction is interpreted. Mark awarded for correct 1:1 or 0..1 labels with justification.
Common Mistakes

Don't lose easy marks

1
Leaving the visibility symbols off attributes and methods — CAIE mark schemes always look for + (public) and - (private). Forgetting these loses marks even if the attribute names and types are correct.
2
Drawing inheritance arrows the wrong way — the arrow always points TO the superclass (parent), not to the subclass. "Dog inherits from Animal" = arrow from Dog pointing to Animal.
3
Confusing aggregation and composition — both are "has-a" relationships but they differ in lifetime dependency. Composition = parts CANNOT exist without the whole. Aggregation = parts CAN exist without the whole. The exam often asks you to distinguish them with an example.
Topic Summary — 4.2.1

What You Need to Know

CLASS BOX FORMAT
3 sections: class name | attributes (- name : Type) | methods (+ Name(params) : ReturnType). + = public, - = private, # = protected.
RELATIONSHIPS
Inheritance (IS-A, hollow triangle → superclass). Association (HAS-A, solid line). Aggregation (hollow diamond, parts survive whole). Composition (filled diamond, parts die with whole).
MULTIPLICITY
1 (exactly one), 0..1 (zero or one), 1..* (one or more), 0..* (zero or more). Always label both ends of an association line.
CSZone

Next Video

4.2.2
Design Patterns
Observer · Strategy · Factory · Singleton
Head to CSZone.co.uk for the complete worksheet, quiz, and interactive tools