Design Patterns : Observer Pattern
Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
Use Observer pattern when
- An abstraction has two aspects, one dependent on the other. Encapsulating these aspects in separate objects let you vary and reuse them independently.
- A change to one object requires changing others, and you don’t know how many objects need to be changed.
- An object should be able to notify other objects without making assumption about who these objects are. In other words, you don’t want these objects tightly coupled.
[Design Patterns – Gamma, et al, 1995]