2009 Observer

2009 Observer - Observer Problem: There are many objects...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Fall 2009 ACS-3913 Ron McFadyen 1 Observer Problem : There are many objects (subscribers) needing to know of the state changes, or events, of another object (publisher), and we want to keep the coupling low. Solution : Define a subscriber or listener interface that is implemented by the subscribers. Situations: Text example: A user interface object, a window, needs to be informed when a domain object changes In some distributed meta-data environments, replicas need to be notified when the source changes Alarm systems need notification of alarms being triggered Also known as Publish-Subscribe
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Fall 2009 ACS-3913 Ron McFadyen 2 the display must reflect the correct total There is a requirement for a window to be updated whenever the total value of the sale changes
Background image of page 2
Fall 2009 ACS-3913 Ron McFadyen 3 Observer Text example. There is a requirement for a window to be updated whenever the total of the sale changes A subscriber interface, PropertyListener, is defined. SaleFrame1 is defined to inherit the PropertyListener interface. This will allow SaleFrame1 to be alerted of changes in the value of the sale total A reference to the Sale is passed to SaleFrame1 when SaleFrame1 is initialized. This allows SaleFrame1 to subscribe to the Sale instance The Sale only knows of objects that subscribe to it; it does not know what class of object they are - so, coupling is kept low.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Fall 2009 ACS-3913 Ron McFadyen 4 The Observer Pattern in a DCD Sale is a publisher and needs to be able to attach observers ( addPropertyListener ) and notify (via publishPropertyEvent message) its observers when an event of
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/17/2010 for the course ACS ACS-3911 taught by Professor Chen during the Spring '10 term at Windsor.

Page1 / 19

2009 Observer - Observer Problem: There are many objects...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online