5 | | |
6 | | Interfaces are declared in much the same way except the keyword is '''interface''' and method and property bodies are not defined. |
7 | | Interface hierarchies (SuperInterfaces) can also be specified using '''inherits''' |
8 | | |
9 | | Instance variables are declared within the class using keyword '''var'''. |
10 | | {{{ |
11 | | var <variableName> [ as <Type>] [ is <AccessModifiers>] |
12 | | var _<variableName> [as <Type>] |
13 | | |
| 6 | === Class Grammar === |
| 7 | {{{ |
| 8 | class <className> |
| 9 | [is <AccessModifiers>] |
| 10 | [has <Attributes>] |
| 11 | [inherits <BaseClassName> ] |
| 12 | [implements <InterfaceName> [, <InterfaceName>]...] |
| 13 | [<DocString>] |
| 14 | |
| 15 | [ |
| 16 | [<Variables>] |
| 17 | [<Properties>] |
| 18 | [<Methods> |
| 19 | [<ClassEnums>] |
| 20 | [<Sigs>] |
| 21 | [<Invariants>] |
| 22 | [<Tests>] |
| 23 | [<SharedClause>] |
| 24 | ]... |
| 25 | }}} |
| 26 | |
| 27 | == Interfaces == |
| 28 | |
| 29 | Interfaces are declared in much the same way except the keyword is '''interface''' and method and property bodies are not defined.[[BR]] |
| 30 | Interface hierarchies (!SuperInterfaces) can also be specified using '''inherits''' |
| 31 | |
| 32 | === Interface Grammar === |
| 33 | {{{ |
| 34 | interface <InterfaceName> |
| 35 | [is <AccessModifiers>] |
| 36 | [has <Attributes>] |
| 37 | [inherits <BaseInterfaceName> [, <BaseInterfaceName>]... ] |
| 38 | [<DocString>] |
| 39 | |
| 40 | [ |
| 41 | [<Properties>] |
| 42 | [<Methods> |
| 43 | [<ClassEnums>] |
| 44 | [<Sigs>] |
| 45 | [<Invariants>] |
| 46 | [<SharedClause>] |
| 47 | ]... |
| 48 | }}} |
| 49 | |
| 50 | == Instance and Class Variables == |
| 51 | Instance and Class variables are declared within the class using keyword '''var'''. |
| 52 | |
| 53 | === Instance and Class variable definition Grammar === |
| 54 | {{{ |
| 55 | var <variableName> [as <Type>] [is <AccessModifiers>] |
| 56 | [<DocString>] |
| 57 | |
| 58 | var _<variableName> [as <Type>] = <initialValue> |
| 59 | [is <AccessModifiers>] |
| 60 | [has <Attributes>] |
| 61 | [<DocString>] |
| 62 | }}} |
| 63 | e.g. |
| 64 | {{{ |
17 | | }}} |
18 | | |
19 | | _ prefix - private ( and directly accessable in methods) |
20 | | without prefix - public (by default ) override using is syntax access using . |
21 | | |
22 | | class variable access modifier '''shared''' as in '''is shared''' |
23 | | - how initialize?? |
24 | | |
25 | | |
26 | | Initializer/constructor |
27 | | |
28 | | properties |
29 | | |
30 | | accessing baseclass methods |
31 | | |
32 | | ==Example == |
| 69 | var t as int = 99 |
| 70 | is protected, shared |
| 71 | """ |
| 72 | Temporary backup value |
| 73 | """ |
| 74 | |
| 75 | }}} |
| 76 | |
| 77 | If the name is prefixed with an '''_''' its accessType defaults to ''protected'' and it is directly accessable from within the class method code.[[BR]] |
| 78 | |
| 79 | Without that prefix on the name the variables accessType is ''public'' (by default) and |
| 80 | it must be accessed from within method code by prefixing the name with either '''self.''' or just '''.'''.[[BR]] |
| 81 | |
| 82 | In either case the default accessModifier setting can be adjusted with an accessModifier clause. |
| 83 | All Class and Instance variable names must start with a lowerCase Letter |
| 84 | |
| 85 | Class (or static) variables are specified with the access Modifier '''shared''' as in '''is shared''' |
| 86 | e.g. |
| 87 | {{{ |
| 88 | var _x = 100 |
| 89 | def tryx( opnd as int) as int |
| 90 | return _x + opnd |
| 91 | |
| 92 | var y is protected # default public |
| 93 | def tryy( opnd as int) as int |
| 94 | return .y + opnd |
| 95 | |
| 96 | var statX as int = 45 |
| 97 | is shared |
| 98 | def x |
| 99 | print .statX |
| 100 | }}} |
| 101 | |
| 102 | |
| 103 | == Properties == |
| 104 | ++TBDone |
| 105 | |
| 106 | === Properties Grammar === |
| 107 | |
| 108 | == Methods == |
| 109 | |
| 110 | Methods are defined using the keyword '''def''' |
| 111 | |
| 112 | === Method Grammar === |
| 113 | {{{ |
| 114 | }}} |
| 115 | |
| 116 | The initializer or constructor method of a class is a special method called '''init''' which is implicitly called when a class instance is constructed. |
| 117 | Its responsible for setting the contents of a class instance to an initial state. |
| 118 | It doesnt return any value and is not inherited (i.e baseclass initialization must be done with an explicit call to |
| 119 | a baseclass constructor). |
| 120 | |
| 121 | If an init method is not specified the compiler runtime generates a noArg constructor that does nothing. |
| 122 | |
| 123 | Constructor chaining can be done to another constructor in the same class (usually with a different number or Type of args) |
| 124 | or to a Superclass constructor (using '''base.init''') - this call must be the first executable line in the init method. |
| 125 | |
| 126 | ++accessing baseclass methods |
| 127 | |
| 128 | == Example == |