Observer Pattern (if you got some spare time)

Tim Rowe tim at remove_if_not_spam.digitig.cix.co.uk
Tue Jun 17 00:27:49 CEST 2003


On Mon, 16 Jun 2003 19:54:28 +0200, Patrick Useldinger <a at b.c> wrote:

>Hi,
>following a previous thread on Patterns, I ended up reading the famous 
>book by Gamma et al., and implemented a "kind of" observer pattern.
>If anyone has some spare time and some interest, take a look at:
>
>http://www.homepages.lu/pu/python.pubsub.py.html

I'm interested in the comment on class PubSub: "you should only need
one instance of this class". It looks to me that it would be quite
hard to manage that on a big project; if you made the one instance a
global that makes class reuse harder. If it's local you have to make
it available to anything that needs it. The approach in Gamma et al
looks to be to be far easier to manage: make each subject handle its
own message queue rather than have a centralised despatcher.  Is there
a reason you didn't go that route, given that Python supports the
necessary multiple inheritance?  Gamma's solution does have memory
management problems in C++ (I've still not worked out how to make it
robust in the presence of observers being deleted), but I don't think
those issues come up in Python.




More information about the Python-list mailing list