Observer Design Pattern

Type

Behavioral Design Patterns focus on how objects interact and distribute responsibilities among themselves. They enhance communication and the assignment of responsibilities between objects. Examples include Observer, Strategy, Command, and State patterns.

Definitions

Subject (Observable):

In the Observer pattern, the Subject (also known as Observable) is a core component that maintains a list of its dependents, called Observers. It sends notifications to Observers when its state changes.

Observers:

Observers are entities that are interested in tracking changes in the state of the Subject. When the state of the Subject changes, it notifies all its Observers.

Concrete Subject:

A specific implementation of the Subject interface or class. It maintains the state and when a change in state occurs, it notifies the list of Observers.

Concrete Observers:

These are specific implementations of the Observer interface. They define the action to be taken when the subject's state changes.

Descriptions

When to use: