Working on an abstraction thing and am trying to figure out proper pattern for naming variables in a setter/getter + calculated case.
There is an attribute of the class that will be either calculated by the code in the class, or it can be specified to contain fixed value by the consumer of the class. Also the consumer might be interested in the calculations.
Sample code (actionscript):
private var _distance:Number; public var calculatedDistance:Number public function get distance():Number {return this._distance;} public function set distance(newDistance:Number):void { this._distance = newDistance layout(); } private function layout() { // do all kinds of things this.calculatedDistance = ... // based on other things calculate the distance if (this._distance != null) { // perform actions with the user set value } else { // otherwise use our calculated value } }
The case works all right but tingles my spidy senses. The variable names feel stiff and might be that i'm trying to solve the issue in a suboptimal way.
Alternatives i could come up with:
- distance vs calculatedDistance
- fixedDistance vs distance
- distanceOverride vs distance
Thing is that this class has a good number of attributes of such nature and the deeper i get the more suspicious it feels.
Thanks for your time!