Properties vs. get/set-methods
Michael 'Mickey' Lauer
mickey at tm.informatik.uni-frankfurt.de
Thu Aug 22 12:12:10 CEST 2002
while trying to become familiar with the newstyle classes I'm now
looking into the properties feature. I don't get the prefered usage
for properties yet. They're not really an alternative to get/set-methods
or are there? I mainly use get/set-methods when I want to save state
and trigger an action, like e.g. in:
def setValue(self, val):
self.val = val
self.updateListeners( val )
When using properties, I can't use val to save the state.
Accessing self.val would lead to infinite recursion here. So, if I
want to save the state, I'd have to introduce another attribute.
So far I guess this would have a performance drawback and a loss of
clarity here just in favour of having the possibility to do
instance.attribute = value instead of instance.setAttribute( value ).
Seems to me that this really is not the scenario properties were invented for!?
What am I missing here?
More information about the Python-list