|The observer design pattern|
The subject (weather service object) to the left and its three observers (weather watcher objects) to the right. The Weather Service Object get its information various sensors.
The Observer is often used to ensure a loose coupling between an application and its user interface
In general, Observer can be used whenever a set of observer objects need to be informed about state changes in a subject object
The loose couple is ensured by observers that subscribe to events from the subjects. Upon interesting and relevant events in the subject, the subject broadcasts to its observers. The observers may then ask the subject to supply additional information.
The main resposibility is shifted from the subject to the observers.
The subject class corresponds to the Weather Service.
The observer class corresponds to a Weather Watcher.
A client class that sets up the subject and the observers, handles subscriptions, and notifies the subject.