Observer pattern thoughts

Bernhard Herzog bh at intevation.de
Fri Mar 7 07:04:08 EST 2003


David Eppstein <eppstein at ics.uci.edu> writes:

> In article <20030306154232.7eb31309.gry at ll.mit.edu>,
>  george young <gry at ll.mit.edu> wrote:
> 
> > Why require an observer to
> >   observable.register(self)
> > and define a member update(self), when it seems like the observable
> > could just take a callable object and call it:
> 
> How do you unregister?  You'd need to store the identity of the callable 
> somewhere, since (e.g. if it's an object method) you can't simply 
> generate it again and get a callable with the same identity.

Bound methods for the same method of the same object are equal even if
the bound methods are not identical:

>>> class C(object):
...     def f(self):
...             pass
... 
>>> c = C()
>>> f1 = c.f
>>> f2 = c.f
>>> f1 == f2
1
>>> f1 is f2

This works for old-style classes as well.

   Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Sketch                                 http://sketch.sourceforge.net/
MapIt!                                           http://www.mapit.de/




More information about the Python-list mailing list