How would you update 100+ variables if something is changed in a different class?
- by N. Lucas
I have a class Grid which produces a graph paper like grid on in the drawing area. I then have 5 other classes for different shapes to draw with; Line, Polygon, Ellipse, Curve, Arc
Now, these 5 classes use an instance of Grid because Grid has a resolution and a scale. Inside Grid I have:
public function set resolution(x:Number):void {
_gap = (modBy10(x) / 10);
_scale = (modBy10(x) / (this.resolution * _scale));
draw();
}
public function get resolution():Number {
return (_gap * 10);
}
public function set scale(x:Number):void {
_scale = (this.resolution / x);
}
public function get scale():Number {
return _scale;
}
/**/
public function scaleLength(x:Number):Number {
return (x * this.scale);
}
public function scaleLengthDown(x:Number):Number {
return (x / this.scale);
}
public function scaleArea(x:Number):Number {
return (x / Math.pow(this.scale, 2));
}
I'm just lost for a solution on how to update every instance of my 5 drawing classes when Grid is changed.
For instance, Polygon is made up of multiple instances of Line, Line(length, angle) where "length" is in either in, ft, cm, or m. If the user wishes to change the scale from say 10ft per 100px resolution.. Is there an easier way than re-drawing every Line inside Polygon?