From: Robert Martin on
On 2006-05-28 02:03:54 -0500, chandra.somesh(a)gmail.com 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(a)objectmentor.com
Object Mentor Inc.? ? ? ? ? ??| blog:??www.butunclebob.com
The Agile Transition Experts??| web:???www.objectmentor.com
800-338-6716? ? ? ? ? ? ? ? ??|



From: Robert Martin on
On 2006-05-28 02:23:21 -0500, "chandra.somesh(a)gmail.com"
<chandra.somesh(a)gmail.com> said:

> well the above SD does solve the problem..but what if i need to
> represent some messages being passed among individual observers...then
> just clubbing the observers as a single object will not be able to
> represent that...can we have individual as well as broadcast messages
> to be represented using the above representation ??

If you are not generating code then the sequence diagrams are not
compiled. No compiler is going to issue an error message. Therefore
you may draw anything that makes sense to you and to your readers.

If you are generating code, then you need a language with a much more
formal syntax than UML.
--
Robert C. Martin (Uncle Bob)??| email: unclebob(a)objectmentor.com
Object Mentor Inc.? ? ? ? ? ??| blog:??www.butunclebob.com
The Agile Transition Experts??| web:???www.objectmentor.com
800-338-6716? ? ? ? ? ? ? ? ??|



From: chandra.somesh@gmail.com on

responding to all

Actually the intent of representing the behavior of observer pattern
using sequence diagram was to mine instances of Design
Patterns(observer in this case) from some legacy code...the constraint
that i put on the behavior is that once the state of Subject
changes..then all its Observers are informed of this change..and each
Observer is sent the update message only ONCE for a single change of
state in the subject...To achieve this i can wrap each update message
inside an "alt" structure and further put this entire structure inside
a "loop" block.....this scheme basically takes care of the order
independence problem...however with the above schema we can have
observers being send zero or more update messages.

I would like to know if this is a valid constarint to put on the
behaviour of observer pattern or we can have an observer receiving more
than one update message per state change of subject?

thanks for all the replies

From: chandra.somesh@gmail.com on
contd....

And if not Sequence Diagram..then what other modelling technique can be
used to effectively represent behaviors of patterns ??

From: H. S. Lahman on
Responding to Phlip...

> How much of this pattern does CORBA have, built-in?

I know nothing about the CORBA internals, so I can't say. I rather
doubt that they do support dynamic ordering, though. Usually it is
tough enough just to guarantee that multiple messages between the same
client and service are delivered in the original order. B-)


*************
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hsl(a)pathfindermda.com
Pathfinder Solutions -- Put MDA to Work
http://www.pathfindermda.com
blog: http://pathfinderpeople.blogs.com/hslahman
Pathfinder is hiring:
http://www.pathfindermda.com/about_us/careers_pos3.php.
(888)OOA-PATH