Wiki Home

Observer Pattern

Namespace: WIN_COM_API
Observer Pattern is one of the 23 Design Patterns elucidated in the most excellent Gamma And Helm book, Design Patterns: Elements of Reusable Object - Oriented Software by Gamma and Helm et al. ISBN 0201633612 , which is cited below:
Intent: Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. (Also known as Dependents, Publish-Subscribe)

Design Pattern Classification: Object Behavioral

Use the Observer Pattern in the following situations -

The following Sequence Diagram illustrates the collaborations between a subject and two observers:

Notice the Observer that initiates the change request postpones its update until it gets a notification from the subject. Notify is not always called by the subject. It can be called by an observer or by another kind of object entirely.

The Observer pattern lets you vary subjects and observers independently. You can reuse subjects without reusing their observers, and vice versa. It lets you add observers without modifying the subject or other observers. See the Gamma And Helm book for common Observer variations and important implementation concerns.

Observer Pattern Example
Two methods and an array added to a form can provide a simple implementation of an observer pattern.
See also: VFP Design Pattern Catalog
Category Design Patterns
( Topic last updated: 2004.02.18 01:32:49 PM )