The Observer pattern provides a way for a component to flexibly broadcast messages to interested receivers.
It defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. The Figure below illustrates the Observer pattern.
The following lists the benefits of using the Observer pattern:
Abstract coupling between subject and observer
Support for broadcast communication
When to Use:
You should use the Observer pattern when:
A change to one object requires changing the other object and you do not know how many objects need to change.
An object should be able to notify other objects without making assumptions about the identity of those objects.