Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, and Michael Stal
"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)
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.
Observer pattern
notification, Observer pattern, Publisher-Subscriber pattern, Buschmann patterns, design patterns, synchronize object state, communication (broadcast), object dependency
any system requiring synchronizing object state across loosely coupled objectsinteractive applications with a flexible human-computer interfacewindowing systems
need to synchronize the state of cooperating componentsthe number and identities of the cooperating components is not known, nor static
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
Simple implmentation of the pattern - Subscriber. Subscriber.javaSimple implmentation of the pattern - Publisher. Publisher.javaSimple implmentation of the pattern. publisher.h