Re: sequence diagram for observer pattern



On 2006-05-28 02:03:54 -0500, chandra.somesh@xxxxxxxxx said:

hi

i have been trying to design sequence diagram for the Observer patterns
but have hit a road block....given below is the brief description...

Given below is a single Subject and three observers (for example
sake)...the Subject is responsible for invoking the notify on it self
whenevr its state changes...and then it sends the update() message to
all its observers....

Subject ObserverA ObserverB ObserverC
|--------l
|<------l notify()
|
| update() |
|------------------------->| |
| update() |
|---------------------------------------------------->|
|
| update()
|-------------------------------------------------------------------------->|

Now this sequence diagram is constrainted in a way that..after a
notify..we have subject sending update to ObserverA and then to
ObserverB and then to ObserverC......
I can show the other variants such as A,C,B and B,C,A and B,A,C and
C,A,B and C,B,A and wrap each of them inside an "alt" block .
However this approach will lead to an explosion of "operands" in case
we have more Observers...so i would like to know how better could i
represent the observer patterns SD with all the possible order of
update() messages taken care of ??

Is there some way that UML 2.0 can represent this behavior ??

0..*
|Subject|------>|Observer|
| |
| 1:Notify |
+-----+ |
| | |
|<----+ |
| |
| 1.1*: Update |
|-------------->|
| |

If you must represent such things, you can do it as in the above. Note that the association between Subject and Observer is shown with a cardinality of 0..* and that there is a * in the sequence number of Update showing that the message repeats. No order is implied, and therefore all orders are valid.

However, I question why you must represent something like this. Drawing pictures of observers is almost certainly a waste of effort unless you have some very particular reason for doing so.

----
Robert C. Martin (Uncle Bob)  | email: unclebob@xxxxxxxxxxxxxxxx
Object Mentor Inc.            | blog:  www.butunclebob.com
The Agile Transition Experts  | web:   www.objectmentor.com
800-338-6716                  |



.



Relevant Pages

  • sequence diagram for observer pattern
    ... i have been trying to design sequence diagram for the Observer patterns ... but have hit a road block....given below is the brief description... ...
    (comp.object)
  • Re: The relativity of simultaneity
    ... The track observer will see the ... predict that the train observer sees the flashes to be simultaneous at ... Two different light rays from the expanding light spheres will hit M'. ...
    (sci.physics.relativity)
  • Re: The relativity of simultaneity
    ... The track observer will see the ... Two different light rays from the expanding light spheres will hit M'.. ... Seto doesn't see things that way. ...
    (sci.physics.relativity)
  • Re: The relativity of simultaneity
    ... The track observer will see the ... Two different light rays from the expanding light spheres will hit M'. ... to answer the simple question you were asked, Seto. ...
    (sci.physics.relativity)
  • ANNOUNCE: pygtkmvc-1.2.1 has been released
    ... Version 1.2.1 of pygtkmvc has been released. ... Model-View-Controller (MVC) and Observer patterns for the PyGTK2 ...
    (comp.lang.python.announce)