Diagram Desk

Observer pattern class diagram

The observer pattern: a subject aggregates observers through an interface that concrete observers implement.

The diagram

Subject+attach(observer) void+notifyAll() voidObserver«interface»+update() voidDisplay+update() voidLogger+update() voidlist
Class diagram · 9 shapes

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

ShapeSymbolConnections
SubjectClassholds +attach(observer) void, +notifyAll() void · → Observer(list)
ObserverInterfaceholds +update() void · ← Subject, Display, Logger
DisplayClassholds +update() void · → Observer
LoggerClassholds +update() void · → Observer

Symbols used here

SymbolMeaning
ClassA box with name, attributes and methods.
InterfaceMarked «interface»; methods only.
RealizationDashed line to the interface, hollow triangle.
AggregationHollow diamond at the whole; parts can live alone.

All class diagram symbols and how to draw

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

More class diagram examples

All SeewolLabs tools