COMP2511 Week 9
Agenda
- Admin Stuff
- Decorator Pattern
- Revision Questions
Admin Stuff
- Assignment 2 is due 5pm this Friday
- Assignment 3 is due 5pm Friday Week 10
- You may switch partners
- Completely optional!
Decorator Pattern
Decorator Pattern
What is it?
Structural design pattern that allows the behaviour of objects to be enhanced placing them into special wrapper objects
What problems does it solve?
Altering behaviours to an object at runtime
Why not just use inheritance?
- Inheritance can only occur at compile time
- Most languages only allow single inheritance
Decorator Pattern

-
ConcreteComponent
and
decorators all conform to an interface -
ConcreteComponent
andConcreteComponent
that have been decorated can be treated in the same way - Decorators hold an instance of the
ConcreteComponent
via composition
Decorator Pattern
Text

Current requirements:
Decorator Pattern
Updated requirements:

Decorator Pattern
Gotchas:
- Why is decorator pattern structural instead of behavioural?
- Difference between strategy and decorator pattern?
Revision Questions
COMP2511 Tutorial 9
By Matthew Liu
COMP2511 Tutorial 9
- 106