This may be a very stupid question, but I still have to ask him. I finish school in about a month, and during my studies I was always taught to use properties instead of public variables.
So, I began to wonder what the advantage is, and I have to say that in some cases I don’t know at all. Of course, this is convenient when you need to perform different logic when setting properties or getting properties, but is there any advantage in using properties when you only get / set a variable? An example of what I mean is shown below (As3).
private var _myVariable:SomeClass;
public function get myVariable():SomeClass{
return _myVariable;
}
public function set myVariable(value:SomeClass):void{
_myVariable = value;
}
So, to repeat and clarify my question: is there any advantage in programming my getter / setter like this, or can I just change the variable to the public one and delete getter / setter?
source
share