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.

Problem

One event must update several features, but directly calling every dependent makes the source tightly coupled and fragile.

Rule

Let observers subscribe to a subject, then notify the current subscriber list whenever relevant state changes.

Run
  1. OBSERVERS register interest in a specific source of change.
  2. SUBJECT changes state and emits a notification to subscribers.
  3. EACH OBSERVER decides independently how to respond to the event.
Output

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.