advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the code for this article
Partners & Affiliates
advertisement
advertisement
advertisement
Average Rating: 4/5 | Rate this item | 1 user has rated this item.
 

Synchronize Data Among Objects with the Publish/Subscribe Design Pattern

Use the Publish/Subscribe design pattern to propagate changes to data between objects in your application.  


advertisement
pplications often need to propagate changes to data to synchronize the state of objects in an application, particularly in user-interface applications where multiple windows can reference the same data. In this type of application, changes to elements of the underlying information must be reflected in all the windows containing references to it.


Take, for example, an application that manages information about people. Multiple windows containing the name of a person might be open at once. If you change the person's name in one window and save, you would expect the name to immediately change in all other windows as well. You can accomplish this functionality by leveraging a design pattern known as Publish/Subscribe. This design pattern is a variation of the Observer pattern (see Figure 1) described in Design Patterns, Elements of Reusable Object Oriented Software, a work many consider the original design patterns book. In the Observer pattern, an object (the Observer) registers to listen for events from another object (the Subject); the Observer is implicitly aware of the Subject.
nbsp;
Figure 1 | Click here to get a close-up view of the Observer Pattern.

The Publish/Subscribe (see Figure 2) variation of this pattern introduces the Event Channel, a layer of separation between the Subject and the Observer. This layer removes the binding between the Observer and the Subject and creates a loosely coupled relationship between the two.
 
Figure 2 | Click here to get a close-up view of the Publish/Subscribe Pattern.

The Event Channel can be described as a messaging center that routes events. The Publisher (know in the Observer pattern as the Subject) publishes events to the Event Channel. The Event Channel is responsible for disseminating the events to all of the Subscribers (know in the Observer pattern as the Observer). An application may contain one or more Event Channels, each disseminating different types of events to interested Subscribers. Also, whereas in Observer the events come only from a specific source, in Publish/Subscribe any object that is aware of the Event Channel may publish an event.

This architecture removes the dependency between the Observer and Subject, resulting in a more generic design for your application. Also, by requiring no direct relationship between the Publisher and the Subscriber, it increases the maintainability of your application.

  Next Page: How the Publish/Subscribe Pattern Is Applied


Page 1: IntroductionPage 3: How EventApp Works
Page 2: How the Publish/Subscribe Pattern Is Applied 
Please rate this item (5=best)
 1  2  3  4  5
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs