Mediator
The other way to cut coupling. Where Observer’s publisher knows nothing about its subscribers, a mediator knows all of them and holds the coordination logic. That is its value and its failure mode: every rule you cannot place anywhere else ends up in the hub, and the hub becomes a God Object.
Structure
classDiagram
class Mediator {
<<interface>>
+notify(sender, event)
}
class DialogMediator {
+notify(sender, event)
}
class Component {
#mediator: Mediator
}
class Button
class TextField
class Checkbox
Mediator <|.. DialogMediator
Component o--> Mediator : knows only the hub
Component <|-- Button
Component <|-- TextField
Component <|-- Checkbox
Telling It Apart
Patterns whose structure looks the same but whose intent does not. See the Confusing Pairs reference.
- Observer — Notify a set of subscribers automatically when state changes; the publisher does not know who is listening.