The Observer is one of the behavioral patterns catalogued in the 1994 “Design Patterns” book by Gamma, Helm, Johnson, and Vlissides. Its intent is to define a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically. The object being watched is called the subject, and the dependents are called observers.
In a typical implementation the subject maintains a list of registered observers and exposes methods to attach and detach them. When the subject’s state changes, it walks its list and calls a notification method on each observer, which then queries the subject for the new state. This keeps the subject decoupled from the concrete classes of its observers, since it only knows that they implement the agreed observer interface.
The pattern is the basis of event and listener systems found throughout user interface toolkits, and it underlies the separation between model and view in the Model-View-Controller arrangement. It is also a conceptual ancestor of modern reactive programming, in which streams of changes propagate to subscribers.
In an interview Erich Gamma used the listener relationship as an illustration of favoring object composition over inheritance: rather than subclassing to react to changes, an object registers as an observer and is plugged in, reducing coupling between the parts. This reflects one of the two design principles the authors emphasized across the whole catalogue.