Steve said:
"none <"@bag.python.org wrote:
It seems particularly odd to want to put getters and setters behind
property access. What does the extra layer buy you?
The purpose is that there is more to the accessors then I posted.
The setters do some 'mark dirty' bookeeping whenever the object state
changes. (I had coded something similar in a prior project but had
forgotten a bit of my own work...in that project the setters also did
some event signaling as the objects were part of an Observer-Observable
pattern)
The getters also have some code in them for dealing with default values
if the given variable behind the property does not exist (which happened
when I was pickling objects and the class structure changed over time;
it was helpful to be able to have the getter be able to check if the
variable existed and, if not, provide a default value...a way of
migrating objects to new class definitions)
So, the use of properties allowed me let clients of the class to use
direct access syntax... o.value versues o.value() or o.value = 123
versus o.value(123) ...but still allow me to do the bookkeeping needed
for my object state. The use of the _getProperty() and _setProperty()
and using lambdas in the actual property definition allowed me to have a
default setter/getter of sorts so I didn't need to write a seperate
getter and setter method for each variable
Take care,
Jay