← Back to PatternPip

OBSERVER / THE IDEA IN A MINUTE

One change.
Several interested listeners.

Observer lets objects subscribe to events from another object, so each can react when something changes.

The publisher keeps a list of interested observers. It sends each one a notification through the same contract. The caller controls who joins and who leaves.

What changes?
The listeners interested in an event.
What stays stable?
The publisher and the notification contract.
Who manages the connection?
The caller subscribes listeners and cleans up when they leave.

WATCH THE CONNECTIONS

One reading. Only interested listeners.

Try it yourself

Choose who subscribes, then publish a reading. Watch it reach only the connected panels.

THE PUBLISHER

Weather station

18 °C

2 of 3 panels subscribed

Display

No reading yet

Shows the latest reading

History

No reading yet

Remembers the last five

Frost alert

No reading yet

Warns at 0 °C or below

Display and History are subscribed. Publish a reading to see them react.

Try this: publish once, unsubscribe Display, then subscribe Frost and publish −4 °C.

Subscriptions change. The station’s notification code stays the same. Reduced motion is on; readings update immediately.

Useful when the audience changes.

Several independent objects need to react to the same event, and listeners join or leave over time.

Connections need care.

Subscriptions add lifecycle work and make the call flow less obvious. A direct call may be simpler for one fixed receiver. Observer does not automatically make delivery asynchronous or reliable.

Choose your next step.