Re: sequence diagram for observer pattern



Responding to Chandra.somesh...

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?

As a practical matter I think the number of notifications a given Observer gets per source state change depends upon the source, not the Observer pattern. That is, conceptually we have:

(1) source state changes.
(2) source generates message to announce state change.
(3) announcement message triggers broadcast notification to every Observer (usually echoing (2)).

That is, (1) and (2) are something the source does while (3) is something the Observer pattern handles. I would expect an implied constraint on the Observer pattern execution semantics that each Observer should receive exactly one notification per announcement message generated by the source.

However, if the source chooses to generate multiple announcement messages per state change, that is a source issue rather than an Observer pattern issue. (Though obviously that could get murky in practical implementations of the Observer pattern.)


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

H. S. Lahman
hsl@xxxxxxxxxxxxxxxxx
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



.



Relevant Pages

  • Re: sequence diagram for observer pattern
    ... Actually the intent of representing the behavior of observer pattern ... 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 ...
    (comp.object)
  • Re: Observer pattern limitations
    ... objects to need to cache the results of calculations. ... However, you're talking about the observer pattern, not about caches. ... dependents into memory - even dependents that aren't themselves being ...
    (comp.object)
  • Re: Question observer design pattern .. more
    ... Responding to Forums_mp... ... However that degree of coupling is neither necessary nor desirable in most practical situations where Observer is applicable. ... Note that in this scheme the R2 registration can be instantiated by any object that understands the context, not necessarily the Listener. ... The Subject does something to change the state of the solution and it generates a message to announce that state change. ...
    (comp.object)
  • Re: Observer pattern limitations
    ... Basically it is to throw away the observer pattern ... (unless you're doing a trivial problem that (provably) ... Over-use of observer leads to the problems you so well described. ... Abstraction is a double-edged sword. ...
    (comp.object)
  • Re: Client/Service relationships & Flow of Requirements.
    ... It doesn't even need to know the Observer exists to do that. ... Should the Subject send the message for any state change it has, ... which are orthogonal to defining responsibilities. ...
    (comp.object)