[Zope-dev] Product upgrades
Tim Hicks
tim@sitefusion.co.uk
Wed, 23 Jan 2002 14:20:08 -0000
<snip>
> Basically, if you want to have a new attribute, say, myNewAttribute,
> instead of doing::
>
> class SomeClass(...):
>
> def __init__(self,...):
> ...
> self.myNewAttribute = something...
>
> you do::
>
> class SomeClass(...):
>
> _myNewAttribute = None
>
> def myNewAttribute(self):
>
> if self._myNewAttribute is None:
> self._myNewAttribute = something
>
> return self._myNewAttribute
>
>
> Of course this means that you can only access it as
> 'self.myNewAttribute()' instead of 'self.myNewAttribute', because you
> never know when it will already be initialized. Actually, you can know
> when it is not initialized, because it will be None, but resist the
> temptation and let myNewAttribute() do it for you. That's what
> encapsulation is for.
>
> You don't have to worry about updating old versions because, if the old
> instance doesn't have _myNewAttribute then it will be taken from the
> class. And the myNewAttribute() method will always be taken from the
> class anyway (even for old versions of your object).
Leo,
thanks very much. That was just what I was after.
much appreciated
tim