Re: Observer pattern limitations



Responding to Barrett-Lennard...

The observer pattern is fundamental to OO, because it is so common for
objects to need to cache the results of calculations. Display pixels
on the screen essentially represent a cache, and display redrawing is a
common use case for the observer pattern.

Basically I agree with everyone else. The problems you cite are design
problems that exist whether Observer is used or not.

I think this paragraph pretty much describes the issue. You seem to be
regarding Observer as an integral part of a particular problem. But
Observer is a solution to a much simpler and more general problem:
providing notification to other objects that the state of the object in
hand has changed. IOW, it is just an infrastructure for addressing
announcement messages in an asynchronous environment.


Exactly what distinction are you drawing? The observer pattern is
mostly used for providing state change notifications. Who would be
interested in such notifications? I call these dependents or caches.

I am drawing a distinction between the design problems you cited and the design problem that Observer resolves. The /only/ problem that observer addresses is that object A needs to know when object B changes and different members of [A] may need to know in different contexts. Why object A needs to know that is part of a different design problem, such as one of those you cited. IOW, the problem context, such as updating a cache, in which Observer is used it not relevant to its use.

What those other objects do in response to that notification is part of
a different problem solution in the context where Observer is used. It
is only in the design of that solution that your issues arise. That
problem solution will determine any necessary protocols and,
consequently, what messages need to be addressed by Observer.


That is exactly what I'm discussing in my post: how do you make the
observer pattern work correctly in practise.

Solve the design problems you cited first. Then if that solution requires that some object in that solution needs to know that some other object changed, Observer may be useful to provide the notification.

In most of the cases you cited you will need to establish some sort of multi-message protocol between the relevant objects and probably internal state machines. Those protocols will define what announcement messages (e.g., events) need to be generated and to whom they should go. If the execution context changes so that different receivers need to participate at different times, /then/ you need Observer to provide the context registration to dispatch the messages to the right object. (If the receivers don't change with context, then simple associations will probably be a better solution than Observer.)


Why don't you discuss the actual content of my post, rather than merely
the introduction?

Because the basic problem is failing to separate the concerns of different problems and the first paragraph most clearly illustrates that. The rest of the post is about specific problems that are not directly related to using Observer.


*************
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: 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)
  • Observer pattern limitations
    ... objects to need to cache the results of calculations. ... common use case for the observer pattern. ... an observer decides to attach or detach to/from the subject. ...
    (comp.object)
  • Re: Observer pattern limitations
    ... objects to need to cache the results of calculations. ... problems that exist whether Observer is used or not. ... a different problem solution in the context where Observer is used. ... Observer may be useful to provide the notification. ...
    (comp.object)
  • Re: Observer pattern limitations
    ... objects to need to cache the results of calculations. ... problems that exist whether Observer is used or not. ... What those other objects do in response to that notification is part of ... a different problem solution in the context where Observer is used. ...
    (comp.object)
  • Re: Coextensive properties?
    ... Quine's "Der" operator to reduce a two place predicate such as ". ... context C such that the object ... ... But we must now explicitly relativize this before we can apply the "Der" ... P by an ideal observer who would conform to all clauses of D1." ...
    (sci.logic)

Loading