Observer Pattern

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. 

UML Representation

Benefits

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 don’t 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.
Subpages (1): Observer Pattern Example
Comments