Observer
Opens the communication module. The publisher not knowing its subscribers is the whole point. Read it against Flow and StateFlow and ask which of the classic Observer problems – leaked subscriptions, undefined delivery order, no backpressure – the coroutine library actually solved, and which it just moved.
Structure
classDiagram
class Subject {
-observers: List~Observer~
+attach(o)
+detach(o)
+notify(event)
}
class Observer {
<<interface>>
+update(event)
}
class ConcreteObserverA {
+update(event)
}
class ConcreteObserverB {
+update(event)
}
Subject o--> Observer : does not know which
Observer <|.. ConcreteObserverA
Observer <|.. ConcreteObserverB
Telling It Apart
Patterns whose structure looks the same but whose intent does not. See the Confusing Pairs reference.
- Mediator — Replace direct references between objects with a hub that coordinates them.