Pattern:
Publisher-Subscriber


Author

Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, and Michael Stal

Intent

"The Publisher-Subscriber design pattern helps to keep the state of cooperating components synchronized. To achieve this it enables one-way propagation of changes: one publisher notifies any number of subscribers about changes to its state." (Buschmann, F., R. Meunier, H. Rohnert, P. Sommerlad, and M. Stal. Pattern-Oriented Software Architecture: A System Of Patterns. West Sussex, England: John Wiley & Sons Ltd., 1996)

Motivation

One dedicated component takes the role of the publisher. All components dependent on changes in the publisher are its subscribers. The publisher maintains a registry of currently-subscribed components. Whenever a component wants to become a subscriber, it uses the subscribe interface offered by the publisher. Analogously, it can unsubscribe. Whenever the publisher changes state, it sends a notification to all its subscribers. The subscribers in turn retrieve the changed data at their discretion. For a more detailed Motivation description for this pattern see: Buschmann, F., R. Meunier, H. Rohnert, P. Sommerlad, and M. Stal. Pattern-Oriented Software Architecture: A System Of Patterns. West Sussex, England: John Wiley & Sons Ltd., 1996.

See Also

Observer pattern

Thumbnail

Keywords

notification, Observer pattern, Publisher-Subscriber pattern, Buschmann patterns, design patterns, synchronize object state, communication (broadcast), object dependency

Business Domains

any system requiring synchronizing object state across loosely coupled objectsinteractive applications with a flexible human-computer interfacewindowing systems

Problem Forces

need to synchronize the state of cooperating componentsthe number and identities of the cooperating components is not known, nor static

Benefits

allows variance in a products internal representationenhanced maintainability and extensibility of the systemflexibility in the way requests are activatedprovides control to single or multiple instancesprovides support for broadcast communication

Implementation Files

Simple implmentation of the pattern - Subscriber. Subscriber.javaSimple implmentation of the pattern - Publisher. Publisher.javaSimple implmentation of the pattern. publisher.h



Generated on Fri Oct 20 10:51:18 GMT+02:00 2000 by Framework Studio