I’ve adopted an existing program at work (lead developer left) and have to finish it up. I’ve been programming for a good decade or more in various languages (Perl and Java mainly) so AS3 is a bit new to me. Fortunately unlikely my failed attempts at AS2, AS3 makes more sense as a language.
The previous programmer has used a notation that I understand, but am unfamiliar with. I’ve been calling it the “magic” get/set.
It looks like this:
public function get Width():Number {
return this.width;
}
public function set Width(value:Number):void {
this.width = value;
}
When used they make it look like you are talking to the property directly (other than the case – where this programmer used leading caps for the get/set methods and lowercase for the property itself)
Now, I’m use to accessor methods, but they tend to be just regular looking methods. getWidth(), setWidth(value). When I call them I know I’m using a method to access a variable (that is most likely private).
I’m failing to see the advantage/appeal of this new get/set thing. I find it confusing that some methods in the class are accessed like methods but these get/set ones are accessed like a straight property (but aren’t).
Am I missing some big advantage here? Can they do something else that I’m not aware of? Also, what are they really called so I can look them up? “Magic” doesn’t seem to be the common term! I feel unnecessarily antagonistic toward this new thing (and you kids get off my lawn!)