The observer pattern regulates communication between an object (called a subject) and other objects (observers) that want to react to changes in the subject. Instead of checking periodically for changes, observers register their interest with the subject and are notified about the changes with some callback or messaging mechanism.
If you subscribe to a magazine, you don't go to the publisher every day to check if a new edition is ready. Rather, you wait until the publisher sends you each issue.
This Gang of Four pattern is a basic part in distributed event handling systems. For example, a Model-View-Controller architectural pattern is always implemented with some application of the observer pattern.
The Live Binding mechanism that's in Delphi is also based on the observer model. It uses the observer mechanism built into the component library (the
Any implementation of the observer pattern follows the following steps:
- The observer registers its interest...