Download presentation
Presentation is loading. Please wait.
1
Observer Pattern Example
From: Designed Patterns Explained by Shalloway & Trott; Addison-Wesley; P The Observer Pattern defines a one to many dependency between objects so that when one object changes state, all its dependents are notified automatically Observers: objects that want to be notified of a certain event. It must have an update method whereby it is notified of an event. Subject: the object that triggers the event. It must implement: attach (observer) - add an observer to its list of observers detach (observer) - remove an observer from … notify () - goes through its list of observers calling each observer’s update method various methods to allow an observer to get additional information March 2002 R McFadyen
2
Observer Pattern Example
Whenever a new customer is entered send a welcome letter verify the customer’s address with the post office send letter with coupons to new customers within 20 miles of the company’s “brick and mortar” stores. Four classes from the problem domain: Customer, WelcomeLetter, AddrVerification, BrickAndMortar Applying the Observer pattern results in Customer being the Subject; the others will be Observers Altogether: 6 classes March 2002 R McFadyen
3
Class Diagram Subject Observer +update() Customer +attach() +detach
+notify() +update() WelcomeLetter Customer +attach() +detach() +notify() +getState() +setState() AddrVerification BrickAndMortar March 2002 R McFadyen
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.