| id |
behavioral/observer |
| name |
Observer |
| aliases |
publish-subscribe |
listener |
event-handler |
|
| guide_url |
|
| problem |
Notify interested parties when something changes, without the subject knowing who they are. |
| symptoms |
react to changes |
event listeners |
pub/sub |
on_change callbacks |
model updates views |
|
| verdict |
pythonic |
| caveats |
Observers are callables — an Observer ABC with one update() method is a function with extra steps. |
Decide the failure policy: one raising observer can silence the rest. Notify inside try/except or document that observers must not raise. |
|
| stdlib_sightings |
concurrent.futures.Future.add_done_callback |
asyncio.Future |
|
Broadcast a change to whoever subscribed, in order, without the subject
knowing its audience. Verdict: pythonic — observers are callables in a
list; the only real design decisions are order and failure policy.
uv run python -m patterns.behavioral.observer.examples.order_events.main