getters/setters
| Definition: |
class identifier private type field public function get_field() return field end function public procedure set_field(type v) field = v end procedure end class |
| Description: |
If attempts to fetch or modify a private field would otherwise trigger a fatal error, but a suitable public get_field function or set_field procedure exists, it is invoked instead. Obviously when neither routine is present, the field is properly private. With only a getter, the field is read-only, and with only a setter it would be write-only. With both, it looks public, but you can validate inputs and/or perform additional tasks. |
| pwa/p2js: | Not supported. |
| Example: |
class test
private string s = "1"
public function get_s()
printf(1,"get_s() called\n")
return s
end function
public procedure set_s(string v)
printf(1,"set_s(%s) called\n",v)
s = v
end procedure
end class
test t = new()
?t.s -- get_s() called, "1"
t.s = "2" -- set_s(2) called
?t.s -- get_s() called, "2"
The use of private and public above is in fact unnecessary, since it matches the default behaviour. |
| Implementation: | As per struct |
| See Also: | class |