3 `var`, used inside concrete and abstract classes, declares attributes. Attributes require a static type and can possibly have an initial value (it may be any kind of expression, even including
12 if k > x then self.i = k - x else self.i = 0
17 Note that from an API point of view, there is no way to distinguish the read access of an attribute with a normal method neither to distinguish a write access of an attribute with a setter. Therefore, the read access of an attribute is called a getter while the write access is called a setter.
20 var x = foo.bar # Is bar an attribute or a method?
21 foo.bar = y # Is bar an attribute or a setter?
22 # In fact, we do not need to know.
25 ## Visibility of Attributes
27 By default, a getter is public and a setter is private. The visibility of getters can be precised with the `private` or `protected` keywords. The visibility of setters can be specified with an
28 additional `writable` keyword.
33 protected var pro_pri: Int
34 var pub_pub: Int is writable
35 private var pri_pro: Int is protected writable
36 var pub_pri2: Int is private writable # the default
40 ## Redefinition of Attributes
42 Getters and setters of attributes behave like genuine methods that can be inherited and redefined. Getters and setters can also redefine inherited methods. `redef var` declares that the getter is
43 a redefinition while `redef writable` declares that the setter is a redefinition.
47 fun derp: Int is abstract
48 fun derp=(o: Int) is abstract
52 redef var derp is redef writable
56 redef fun derp do return 1
57 redef fun derp=(o) do end