Using settable properties to update eager attributes
In several of the previous recipes, we've looked at the important distinction between eager and lazy computation. See the Designing classes with lots of processing recipe for an example of eagerly computing a result and setting object attributes. See the Using properties for lazy attributes recipe for a way to use properties to lazily compute a result.
When an object is stateful, then attribute values must be changed throughout the object's life. It's common to use methods to eagerly compute attribute changes, but this isn't really necessary.
We have the following choices for stateful objects:
- Set attribute values via methods:
- Compute results eagerly, putting results in attributes
- Compute results lazily, using properties that have syntax that looks like a simple attribute
- Set values via attributes:
- If results are computed lazily via properties, then the new state can be reflected in these calculations
What can we do if we want to use attribute...