Observer pattern class diagram
The observer pattern: a subject aggregates observers through an interface that concrete observers implement.
The diagram
Reading it step by step
- 'Subject' (class): 0 attributes, 2 methods.
- 'Observer' (interface): 0 attributes, 1 methods.
- 'Display' (class): 0 attributes, 1 methods.
- 'Logger' (class): 0 attributes, 1 methods.
- 'Subject' aggregates 'Observer' (list).
- 'Display' implements 'Observer'.
- 'Logger' implements 'Observer'.
Shape by shape
| Shape | Symbol | Connections |
|---|---|---|
| Subject | Class | holds +attach(observer) void, +notifyAll() void · → Observer(list) |
| Observer | Interface | holds +update() void · ← Subject, Display, Logger |
| Display | Class | holds +update() void · → Observer |
| Logger | Class | holds +update() void · → Observer |
Symbols used here
| Symbol | Meaning |
|---|---|
| Class | A box with name, attributes and methods. |
| Interface | Marked «interface»; methods only. |
| Realization | Dashed line to the interface, hollow triangle. |
| Aggregation | Hollow diamond at the whole; parts can live alone. |
Diagram text
Paste this text into the editor to get the same picture, then change the names to fit your own work.
# Observer pattern class diagram
classDiagram
class Subject {
+attach(observer) void
+notifyAll() void
}
class Observer {
<<interface>>
+update() void
}
class Display {
+update() void
}
class Logger {
+update() void
}
Subject o-- Observer : list
Observer <|.. Display
Observer <|.. Logger