durusmail: durus-users: subclassing PeristentDict
subclassing PeristentDict
2006-02-06
2006-02-06
2006-02-06
subclassing PeristentDict
Jeff Bauer
2006-02-06
David Binger wrote:
> On Feb 5, 2006, at 7:36 PM, Jeff Bauer wrote:
>>     class Staff(PersistentDict):
>>         pass
>>
>>   AttributeError: 'Staff' object has no attribute 'data'
....
>
> I assume that the non-working Staff class had an
> __init__ implementation that did not call
> PersistentDict.__init__.  Am I right about that?

Yep. ;-)  Just playing around with things at the
moment.

> We usually avoid subclassing the basic container classes.
> Our common pattern is to make a special purpose class that
> has, say, a PersistentDict as an attribute value.
> There are advantages and disadvantages to this, but one
> advantage is that it avoids the possible confusion
> that you point out.

Thanks. Any advice with basic usage patterns is appreciated.
For straight-up dicts, attribute = PersistentDict() makes
sense.  For classes that exhibit dict-like behavior, ingrained
habits would lead me to subclass PersistentDict.  But I'm
not so old that I can't change my habits. ;-)

--
Jeff Bauer      http://serpentaddiction.blogspot.com
Rubicon, Inc.   http://www.rubic.com
reply