Implementation Patterns for the Observer Pattern

By: J.J. Kim, K.M. Benner
Published in: PLoPD2
Pages: 75-86
Category: Behavioral, Design Process

Summary: Extensions to Observer [Gamma+95]

Pattern: Conduit of Subject Change

Pages: 76-78

You're using Observer [Gamma+95]. Observer objects are receiving insufficient detail about the update. Send an update message that comprises four lists: Add (object creations), Remove (object deletions), Modify (object modifications), and Container (subject containment relationships).

Pattern: One Message per Change Request

Pages: 79-80

You're using Conduit of Subject Change. You want the simplest possible update design where the subject can simply store any and all state change information. When a change request is initiated, a message object is created. Use the message class defined in Observer Update Message. When the subject changes state, it stores affected objects in the appropriate list.

Pattern: One Message per Affected Object

Pages: 80-81

You're using Conduit of Subject Change. You want a simple update design without the danger of false hits that can occur in One Message per Change Request. Since a single change request can affect multiple objects, for each affected object generate an update message that relates the object, its containers, and the nature of the change.

Pattern: Optimized Messages per Change Request

Pages: 81-83

You're using Conduit of Subject Change. You want an update design with a minimal number of update messages without false hits. You do not have to worry about a containment relationship for the subject. Provide an algorithm for generating a minimal number of updates.

Pattern: Message Packet

Pages: 84

You're using Observer [Gamma+95]. The system can generate multiple update messages. Some of these messages belong to a group. The message receiver must identify the beginning and end of a series of messages in the same group. Define a message generator that knows when a group of messages is generated. The message generator can package messages into a packet, usually a simple list, and send the packet. The receiver is free to process the messages as needed.

Pattern: Observer Update Message

Pages: 85

You're using Observer [Gamma+95] or any of its refinements. The subject consists of many objects with nested containment relationships. The observer needs to be informed of the subject's state change information, but not depend on the subject's structure. Any state change in the subject can be characterized by a series of new object creations (Add), old object deletions (Remove), and object modifications (Modify) at certain locations. The subject update message consists of four lists: Add, Remove, Modify, and Container. (The Container list indicates the locations where the updates are to be made.)