We'll break this into two parts. First, the general overview of defining settable properties, then the details of how to track state changes:
- Define a class with a meaningful name.
- Provide hidden attributes. These will be exposed as properties:
class Leg: def __init__(self): self._rate= rate self._time= time self._distance= distance.
- For each gettable property, provide a method to compute the property value. In many cases, these will parallel the hidden attributes:
@property def rate(self): return self._rate
- For each settable property, provide a method to set the property value:
@rate.setter def rate(self, value): self._rate = value self._calculate('rate')
The setter method has a special property decorator ...