The Observer pattern is a Gang of Four pattern. It is a pattern made famous by being included in the book Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. The pattern has two key players involved: a Subject and an Observer. A Subject is observed by an Observer. Typically, a Subject holds an internal list of Observers that should be notified when a change happens on the Subject. It is quite common that the Subject is a model and the Observers are some kind of UI component. In short, Subjects should be able to:
- Hold a list of Observers
- Add an Observer
- Remove an Observer
- Notify all Observers when a change happens
The Observer, on the other hand, should only hold one property, and that is an update() method that can be called by a Subject when an update has occurred. The idea behind this...