SE 430 Object Oriented Modeling Dennis Mumaugh Instructor
SE 430 Object Oriented Modeling Dennis Mumaugh, Instructor dmumaugh@cdm. depaul. edu Office: CS&TC 430 Office Hours: Tuesday/Thursday, 4: 15 -5: 45 8 July 2008 SE 430 - Object Oriented Modeling 1/8
Design Patterns 8 July 2008 SE 430 - Object Oriented Modeling 2/8
Publish-Subscribe Pattern name: Publish-Subscribe Pattern q Supports a general purpose method of event notification and indirect communication within a System. Solution: q Create an event notification system so that the Publisher of an event can indirectly notify Subscribers. Achieved by: q Define an Event. Manger class that maintains mappings between events and subscribers. 8 July 2008 SE 430 - Object Oriented Modeling 3/8
Publish-Subscribe Sequence of operations: q Subscriber objects (including windows applets) register for an event by sending a subscription message to the Event. Manager. subscribe(Subscriber. Name, Subscriber. Method. Name, "event. Type 1") q Publisher of an event sends a message to the Event. Manager that the event occurred. signal. Event("event. Type 1") q The Event. Manager finds all subscribers interested in the event "event. Type 1" sends a message to all subscribers of the event with Subscriber. Method. Name() 8 July 2008 SE 430 - Object Oriented Modeling 4/8
Publish-Subscribe Problem solved: q A change in state (an event) occurs within a Publisher of the event and other objects are dependent on or interested in this event (Subscribers to the event). However the Publisher should not have direct knowledge of the Subscribers. v Direct coupling between senders and receivers is not required v A single event can be broadcast to any number of subscribers 8 July 2008 SE 430 - Object Oriented Modeling 5/8
Don’t Talk to Strangers q How to design to reduce coupling to knowledge of the structural connections of objects? v Don’t traverse a network of object connections in order to invoke an operation. v Rather, promote that operation to a “familiar” of the client. q Law of Demeter q The sending object v calls objects whose addresses it knows. v does not look for object addresses contained in other objects. Ø (Doesn’t check the structure of other objects by investigating their object sub-parts) 8 July 2008 SE 430 - Object Oriented Modeling 6/8
Law of Demeter Formal Lo. D q An object method should only send messages to methods in the following kinds of objects: 1) itself (this or self referrals) Ø i. e. return. Value = this. operation. Name (parameters) 2) any object created and instantiated within the method. Ø i. e. Object. Y obj. Y = new Object. Y; 3) an attribute of the object itself. Ø i. e. Object. Z obj. Z; 4) a parameter received by the method. Ø i. e. operation. Name (Object. X obj. X) 8 July 2008 SE 430 - Object Oriented Modeling 7/8
Law of Demeter Are the following objects appropriately visible to each other according to the Law of Demeter restrictions? q Artifact. Description and Audit. Trail? q Exhibit and Tour? q Document and Retrieval. Agent? q Viewer and Directory? 8 July 2008 SE 430 - Object Oriented Modeling 8/8
- Slides: 8