Behavioral pattern · Visual logic
Observer Pattern: One Change, Many Reactions
Observer turns a state change into a broadcast so multiple dependents can react without the source knowing their concrete implementations.
One event must update several features, but directly calling every dependent makes the source tightly coupled and fragile.
Let observers subscribe to a subject, then notify the current subscriber list whenever relevant state changes.
- OBSERVERS register interest in a specific source of change.
- SUBJECT changes state and emits a notification to subscribers.
- EACH OBSERVER decides independently how to respond to the event.
Reactions can be added or removed without teaching the event source about every downstream feature.
Run it in the real world
A price update can refresh the chart, trigger an alert, and write an audit record while the price service knows none of those details.
Go deeper
This is an original explanation and example inspired by Head First Design Patterns. The book covers the complete pattern, design principles, and implementation detail.
Retail links are not affiliate links yet. If that changes, this page will clearly disclose it.