[Python-Dev] Oberver Pattern

Patrick K. O'Brien pobrien@orbtech.com
Fri, 10 May 2002 13:56:33 -0500

[Raymond Hettinger]
> I would like to know what you all think about formalizing an observer
> protocol for python objects.

Interesting question. I'm curious to see the responses this will get. For
discussion sake I'll throw in my dispatcher recipe as an example of a very
loosely coupled alternative to the traditional Observer pattern:


I'm not suggesting that it does exactly what you want. I just want to round
out the discussion. Zope3 is doing something similar with its EventHub, I

There is something about the Observer pattern that I've never fully liked.
It seems to introduce a level of coupling that, to my way of thinking,
"corrupts" the design of the object being observed. In real life, things can
be observed without their knowledge. So why should an observable object have
to keep track of all of its listeners and notify them regularly? That
doesn't seem like the right distribution of responsibility to me. And that
line of thinking lead me to create dispatcher.

But I'm willing to hear about the benefits of your idea. A standardized
implementation might overcome my initial reluctance. So what are the
benefits of formalizing this?

Patrick K. O'Brien