Now I’m just being curious but I wanted to know how much of a difference there is between accessing a variable directly and accessing it through get/set functions.
e.g.
class someClass
{
public var hello:String = "Hello";
private var bye:String = "Bye";
public function someClass(){}
public function getBye():String
{
return bye;
}
public function setBye(newVal:String):Boolean
{
if (newVal != hello)
{
bye = newVal;
return true;
}
else
return false;
}
}
var someVar:someClass = new someClass;
trace someVar.hello; //outputs "Hello"
someVar.hello = "Konnichiwa";
trace someVar.hello //outputs "Konnichiwa"
trace someVar.getBye(); //outputs "Bye"
someVar.setBye("Ja ne");
trace someVar.getBye(); //outputs "Ja ne"
What’s the difference (apart from allowing error checking as shown in someClass.setBye())?
[ot]Edit: [noparse][as2][/as2] doesn’t work![/noparse][/ot]