= Class Definitions = Classes are declared using the '''class''' keyword followed by the classname. [[BR]] The class may have any of the usual [wiki:AccessModifiers access modifiers]. [[BR]] The Superclass inheritance and Interface conformance are indicated with the '''inherits''' and '''implements''' keywords. === Class Grammar === {{{ class [is ] [has ] [inherits ] [implements [, ]...] [] [ [] [] [ [] [] [] [] [] ]... }}} == Interfaces == Interfaces are declared in much the same way except the keyword is '''interface''' and method and property bodies are not defined.[[BR]] Interface hierarchies (!SuperInterfaces) can also be specified using '''inherits''' === Interface Grammar === {{{ interface [is ] [has ] [inherits [, ]... ] [] [ [] [ [] [] [] [] ]... }}} == Instance and Class Variables == Instance and Class variables are declared within the class using keyword '''var'''. === Instance and Class variable definition Grammar === {{{ var [as ] [is ] [] var [as ] = [is ] [has ] [] }}} e.g. {{{ var x as String var _y as int var _ya as int = 47 var z as int is private var t as int = 99 is protected, shared """ Temporary backup value """ }}} All Class and Instance variable names must start with a lowerCase Letter[[BR]] If the name is prefixed with an '''_''' its accessType defaults to ''protected'' and it is directly accessable from within the class method code.[[BR]] Without that prefix on the name the variables accessType is ''public, virtual'' (by default) and it must be accessed from within method code by prefixing the name with either '''this.''' or just '''.''' .[[BR]] In either case the default [wiki:AccessModifier accessModifier] setting can be adjusted with an accessModifier clause.[[BR]] Class (or static) variables are specified with the access Modifier '''shared''' as in '''is shared''' e.g. {{{ var _x = 100 def tryx( opnd as int) as int return _x + opnd var y is protected # default public def tryy( opnd as int) as int return .y + opnd var statX as int = 45 is shared def x print .statX }}} == Properties == ++TBDone === Properties Grammar === ++TBDone == Methods == Methods are defined using the keyword '''def'''. If not specified the returnType is void ( i.e nothing returned) and the [wiki:AccessModifiers access modifiers] are '''public, virtual'''[[BR]] Like variables if the name is prefixed with an '''_''' its access modifier defaults to ''protected'' and it is directly accessable from within the class method code.[[BR]] Without that prefix on the name the methods the accessType is ''public, virtual'' and it must be accessed from within method code by prefixing the name with either '''this.''' or just '''.''' .[[BR]] +++TBD+++ paramlist[[BR]] +++TBD+++ Generics === Method Grammar === {{{ def [as ] [is ] [has ] [] def () [as ] [is ] [has ] [] }}} The initializer or constructor method of a class is a special method called '''init''' which is implicitly called when a class instance is constructed. Its responsible for setting the contents of a class instance to an initial state. It doesnt return any value and is not inherited (i.e baseclass initialization must be done with an explicit call to a baseclass constructor). If an init method is not specified the compiler runtime generates a noArg constructor that does nothing. Constructor chaining can be done to another constructor in the same class (usually with a different number or Type of args) or to a Superclass constructor (using '''base.init''') - this call must be the first executable line in the init method. ++accessing baseclass methods == Example == {{{ #Interfaces interface Audible def makesNoise as String interface Mateable pro mateName as String interface Breedable inherits Mateable pro childName as String # class declaration - note indentation class Bovidae def diet as String return 'Herbivorous Cud Chewing' def nHooves as String return 'four' class Sheep is public, nonvirtual # public is default anyway inherits Bovidae # Superclass implements Audible, Breedable var _lifeSpan as int = 8 is shared # years average # or var lifeSpan as int private shared var _age as int =1 var liveWeight as int is private var _isAlive as bool #shared #_lifespan = 8 def init _age = 1 .liveWeight = 2 _isAlive = true def makesNoise as String return 'Baaaaa' pro mateName as String get return 'Ram' set pass pro childName as String get return 'lamb' set pass def age( byNYears as int) _age += byNYears if _age > _lifeSpan _isAlive = false def gainWgt( wgt as int) .liveWeight += wgt def toString as String is new return 'Sheep:age=[_age], wgt=[.liveWeight], living=[_isAlive]' def main is shared s = Sheep() print 's=[s.toString]' s.age(1) }}}