Game Development Reference
In-Depth Information
Properties with getters/setters
It is possible to define special functions that can be accessed as if they are variables. For in-
stance, we could say foo.someVar = "testing"; , and under the hood, there are
get and set functions that process the testing argument and store it internally.
However, they can also do any other processing on it, for instance, capitalizing the first let-
ter before storing it. So, you're not just doing a variable assignment, but you're calling a
function that sets the variable, and it can do whatever other functions can do:
// JavaScript user:
private var foo = 8; //"backing store"
function get Foo () : int {
return foo;
}
function set Foo (value) {
foo = value;
}
// C# user:
public class MyClass {
private int foo = 8; //"backing store"
public int Foo {
get {
return foo;
}
set {
foo = value;
}
}
}
Search WWH ::




Custom Search