Display
No reading yet
Shows the latest reading
Appearance
OBSERVER / THE IDEA IN A MINUTE
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.
WATCH THE CONNECTIONS
Choose who subscribes, then publish a reading. Watch it reach only the connected panels.
THE PUBLISHER
2 of 3 panels subscribed
No reading yet
Shows the latest reading
No reading yet
Remembers the last five
No reading yet
Warns at 0 °C or below
Display and History are subscribed. Publish a reading to see them react.
Several independent objects need to react to the same event, and listeners join or leave over time.
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.
Start with one display, feel the cost of adding listeners, then connect panels through subscriptions.
Live weather station · optional practiceBACK FOR A REFRESHERReview the roles, subscription lifecycle, TypeScript/Kotlin code, and mistakes to avoid.
Bookmarkable · no walkthrough required