jargon

Comparison

Mediator patternvsObserver pattern

Mediator pattern

the six components stopped calling each other and all called one object in the middle instead.

Replacing many-to-many references between colleagues with a single object that coordinates them. It turns a tangle into a hub, which is a genuine improvement in the tangle and a genuine risk in the hub — the mediator is the class most likely to grow into a god object. It differs from an observer in direction: an observer broadcasts a change outward, a mediator receives events and decides what everyone should do.

Full entry →

Observer pattern

you changed one field and four other things updated, and finding out which four meant reading a subscription list.

A subject holding a list of dependents and notifying each of them when it changes. It is in-process and direct: the subject holds references to its observers, so the two know about each other in a way publish-subscribe deliberately avoids. Its recurring problems are all lifetime problems — observers that are never unsubscribed keep their subject alive, and notification order is an unwritten dependency people come to rely on.

Full entry →

Related comparisons