Observer Design Pattern Explained
The Observer pattern lets an object (the subject) notify a list of dependent objects (observers) automatically whenever its state changes, without the subjec...
Published October 6, 2026
The Observer pattern lets an object (the subject) notify a list of dependent objects (observers) automatically whenever its state changes, without the subject needing to know any details about them.
Why it exists
- Many systems need one part of the code to react whenever something changes elsewhere, without tightly coupling the two parts together
- Without this pattern, the changing object would need direct references to every interested party and would have to call each one explicitly
How to apply it
- Implement it with a subscribe/unsubscribe mechanism and a notify method that calls every registered observer
- This pattern underlies many familiar tools directly: DOM event listeners, and reactive state libraries all follow the same core idea
FAQ
Is this the same as pub/sub?
They're closely related — Observer typically has direct references between subject and observers, while pub/sub usually adds an intermediary (like a message broker) decoupling publishers from subscribers entirely.