[Persistence-sig] Clarification: A simple Observation API
Phillip J. Eby
pje@telecommunity.com
Tue, 23 Jul 2002 21:09:35 -0400
At 09:01 PM 7/23/02 -0400, Phillip J. Eby wrote:
>class aSubject(Observable):
>
> ....
>
> def setFoo(self, foo):
> self.foo = foo
> self.bar = 3*foo
>
> # setFoo modifies multiple attributes, and should send at most
> # one notice of modification, upon exiting.
> setFoo = WritingMethod(setFoo)
Just a quick clarification on the demo code... if a method only sets one
attribute, or if it sets multiple attributes, but you don't care about
consolidating the change events, it's not necessary to declare the method a
WritingMethod. In that case, the __setattr__ hook will issue change events
for each attribute set, unless the method is being called by a
WritingMethod, either directly or indirectly. Use of a WritingMethod
wrapper is only required for methods that set attributes and need the
changes to be ignored, or which manipulate mutable attributes without
actually setting attributes on the instance. Any other use is optional at
the implementor's discretion.