OBSERVER The  Observer  defines a one to many relationship, so that when one object changes state, the others are notified...
<ul><li>Intent </li></ul><ul><li>  Define a one-to-many dependency between objects so that when one object changes state, ...
Illustration a=50% b=30% c=20% e.t.c Subject Change notification Request, modification
<ul><li>Solution: </li></ul><ul><li>The observer pattern describes how to establish these relationships.  </li></ul><ul><l...
Applicability <ul><li>Use the Observer pattern in any of the following situations: </li></ul><ul><li>  </li></ul><ul><li>W...
Structure } *
Collaborations <ul><li>   ConcreteSubject notifies its observers whenever a change occurs that could make its observers’ ...
Collaborations NOTE: How observer object that initiates the change request postpones its update until it gets a notificati...
Consequences <ul><li>Abstract coupling between Subject and Observer </li></ul><ul><li>Support for broadcast communication....
Model
Related patterns <ul><li>Mediator:  By encapsulating complex update semantics, the ChangeManager acts as mediator between ...
Upcoming SlideShare
Loading in …5
×

Observer

680 views
618 views

Published on

Object-oriented analysis and design(OOAD) and Design Pattern Slides UML Slides. for more slides refer www.scmGalaxy.com

Published in: Education, Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
680
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
24
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Observer

  1. 1. OBSERVER The Observer defines a one to many relationship, so that when one object changes state, the others are notified and updated automatically. Some auctions demonstrate this pattern. Each bidder possesses a numbered paddle that is used to indicate a bid. The auctioneer starts the bidding, and &quot;observes&quot; when a paddle is raised to accept the bid. The acceptance of the bid changes the bid price, which is broadcast to all of the bidders in the form of a new bid
  2. 2. <ul><li>Intent </li></ul><ul><li>  Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. </li></ul><ul><li>  Alternative Name: </li></ul><ul><li>  Dependents, Publish-Subscribe </li></ul>Problem: How to handle a common side-effect (i.e. need to maintain consistency between related object)of partitioning a system into a collection of cooperating classes with out making the classes tightly coupled , - which in turn makes classes less reusable.
  3. 3. Illustration a=50% b=30% c=20% e.t.c Subject Change notification Request, modification
  4. 4. <ul><li>Solution: </li></ul><ul><li>The observer pattern describes how to establish these relationships. </li></ul><ul><li>The key objects in this pattern are subject and observer. </li></ul><ul><ul><li>A subject may have any number of dependent observer. </li></ul></ul><ul><ul><li>All observers are notified whenever the subject undergoes a change in state. </li></ul></ul><ul><ul><li>In response, each observer will query the subject to synchronize its state with the subject’s state. </li></ul></ul>
  5. 5. Applicability <ul><li>Use the Observer pattern in any of the following situations: </li></ul><ul><li>  </li></ul><ul><li>When an abstraction has two aspects, one dependent on the other. Encapsulating these aspects in separate objects lets you vary and reuse them independently. </li></ul><ul><li>  </li></ul><ul><li>When a change to one object requires changing others, and you don’t know how many objects need to be changed. </li></ul><ul><li>  </li></ul><ul><li>When an object should be able to notify other objects without making assumptions about who these objects are. In other words, you don’t want these objects tightly coupled. </li></ul>
  6. 6. Structure } *
  7. 7. Collaborations <ul><li>   ConcreteSubject notifies its observers whenever a change occurs that could make its observers’ state inconsistent with its own. </li></ul><ul><li>  </li></ul><ul><li>After being informed of a change in the concrete subject, a ConcreteObserver object may query the subject for information. ConcreteObserver uses this information to reconcile its state with that of the subject. </li></ul>
  8. 8. Collaborations NOTE: How observer object that initiates the change request postpones its update until it gets a notification form the subject.
  9. 9. Consequences <ul><li>Abstract coupling between Subject and Observer </li></ul><ul><li>Support for broadcast communication. </li></ul><ul><li>Unexpected updates. </li></ul>
  10. 10. Model
  11. 11. Related patterns <ul><li>Mediator: By encapsulating complex update semantics, the ChangeManager acts as mediator between subjects and observers. </li></ul><ul><li>  </li></ul><ul><li>Singleton: The ChangeManager may use the Singleton pattern to make it unique and globally accessible. </li></ul>

×