Wiki

Changes between Version 10 and Version 11 of Classes

Show
Ignore:
Timestamp:
05/14/10 08:44:58 (14 years ago)
Author:
hopscc
Comment:

remove interface to own section and expand and cleanup

Legend:

Unmodified
Added
Removed
Modified
  • Classes

    v10 v11  
    11= Class Definitions = 
    22 
    3 Classes are declared using the '''class''' keyword followed by the classname. [[BR]] 
     3A class provides the definition for the type of an object and the variables, properties, events, and methods  that the class comprises.[[BR]] 
     4In addition it may declare tests to exercise the class and contracts or constraints the class must conform to to ensure continuing validity.  
     5 
     6Classes are declared using the '''class''' keyword followed by the name of the class.[[BR]] 
     7The classname must start with an uppercase letter. [[BR]] 
     8 
    49The class  may have any of the usual [wiki:AccessModifiers access modifiers]. [[BR]] 
    5 The Superclass inheritance and Interface conformance are indicated with the '''inherits''' and '''implements''' keywords. 
     10The Superclass inheritance and interface conformance are indicated with the '''inherits''' and '''implements''' keywords. 
     11 
    612=== Class Grammar === 
    713{{{ 
     
    1521 
    1622    [ 
    17     [<Variables>] 
    18     [<Properties>] 
    19     [<Methods> 
    20     [<ClassEnums>] 
    21     [<Sigs>] 
    22     [<Invariants>] 
    23     [<Tests>] 
    24     [<SharedClause>] 
     23        [<Variables>] 
     24        [<Properties>] 
     25        [<Methods> 
     26        [<ClassEnums>] 
     27        [<Sigs>] 
     28        [<Invariants>] 
     29        [<Tests>] 
     30        [<SharedClause>] 
    2531    ]... 
    26 }}} 
    27  
    28  
    29 == Interfaces == 
    30  
    31 Interfaces are declared in much the same way except the keyword is '''interface''' and method and property bodies are not defined.[[BR]] 
    32 Interface hierarchies (!SuperInterfaces) can also be specified using '''inherits''' 
    33  
    34 === Interface Grammar === 
    35 {{{ 
    36 interface <InterfaceName>   
     32 
     33# empty (placeholder) class 
     34class <ClassName>   
    3735    [is <AccessModifiers>] 
    3836    [has <Attributes>] 
    3937    [where <GenericParam> must be <GenericConstraints>] 
    40     [inherits <BaseInterfaceName> [, <BaseInterfaceName>]... ] 
     38    [inherits <BaseClassName> ] 
     39    [implements <InterfaceName> [, <InterfaceName>]...] 
    4140    [<DocString>] 
    42  
    43     [  
    44     [<Properties>] 
    45     [<Methods> 
    46     [<ClassEnums>] 
    47     [<Sigs>] 
    48     [<Invariants>] 
    49     [<SharedClause>]  
    50     ]... 
     41        pass 
    5142}}} 
    5243 
     
    5445 
    5546== Instance and Class Variables == 
    56 Instance and Class variables are declared within the class using keyword '''var'''. 
    57  
     47Instance and Class variables are declared within the class using keyword '''var''' followed by the var name.[[BR]] 
     48Like local variables they may be explicitly typed ( {{{ as <Type> }}} ) and if not are defaulted to type '''dynamic'''. 
     49 
     50An initial value may be specified (if not the var gets its types 'empty' value ( 0, "" or nil)[[BR]] 
     51(Idiomatically its usually preferable to explicitly initialise the var and not explicitly specify the Type). 
     52 
     53[wiki:AccessModifiers AccessModifiers] usually specifying visibility can also be given. 
     54   
    5855=== Instance and Class variable definition Grammar ===  
    5956{{{ 
     
    7471    var t as int = 99 
    7572        is protected, shared 
    76         """ 
    77         Temporary backup value 
    78         """ 
    79  
    80 }}} 
    81  
    82 All Class and Instance variable names must start with a lowerCase Letter[[BR]] 
    83  
    84 If the name is prefixed with an '''_''' (single underscore) its accessType defaults to ''protected'' and it is directly accessible from within the class method code.[[BR]] 
    85  
    86 If the name is prefixed with an '''_ _''' (double underscore) its accessType defaults to ''private'' and it is directly accessible from within the class method code.[[BR]] 
    87  
    88 Without that prefix on the name the variables  accessType is ''public'' (by default) and  
     73        """t is a Temporary backup value""" 
     74 
     75}}} 
     76 
     77All class and instance variable names must start with a lowerCase Letter[[BR]] 
     78 
     79If the name is prefixed with an '''_''' (single underscore) its accessType defaults to '''protected''' and it is directly accessible from within the class method code.[[BR]] 
     80 
     81If the name is prefixed with an '''_ _''' (double underscore) its accessType defaults to '''private''' and it is directly accessible from within the class method code.[[BR]] 
     82 
     83Without that prefix on the name the variables  accessType is '''public''' (by default) and  
    8984it must be accessed from within method code by prefixing the name with either '''this.''' or just '''.''' .[[BR]] 
    9085 
    91 In either case the default [wiki:AccessModifier access ] setting can be adjusted with an access modifier clause.[[BR]] 
    92  
    93 Class (or static) variables are specified with the access modifier  '''shared''' as in '''is shared''' 
     86In either case the default [wiki:AccessModifiers access ] setting can be adjusted with an access modifier clause.[[BR]] 
     87 
     88Class (or static) variables are specified with the access modifier  '''shared''' as in {{{ is shared }}}[[BR]] 
    9489e.g. 
    9590{{{ 
     
    115110== Properties == 
    116111Define a property for the class 
     112 
     113''To be expanded'' 
    117114 
    118115=== Properties Grammar === 
     
    135132 
    136133== Methods == 
     134A method is a code block that contains a series of statements. [[BR]] 
     135A program causes the statements to be executed by calling the method and specifying any required method arguments. 
     136 
    137137Methods are defined using the keyword '''def'''. 
    138138 
     
    161161 
    162162If an init method is not specified the compiler runtime generates a noArg constructor that does nothing. 
    163  
    164 Constructor chaining can be done to another constructor in the same class (usually with a different number or Type of args) 
     163Because this method is 'special' it is declared using '''cue''' rather than '''def'''. See [wiki:Cues cues] 
     164 
     165Constructor chaining must be done explicitly to another constructor in the same class (usually with a different number or Type of args) 
    165166or to a Superclass constructor  (using '''base.init''') - this call must be the first executable line in the init method. 
    166167 
     
    199200}}} 
    200201   
    201 meth takes 3 args , the first and second are inward only and are dynamic and a string respectively, the third is only returned from the method as a string 
    202 sum takes a variable number of integer args 
     202meth takes 3 args , the first and second are inward only and are dynamic and a string respectively, the third is only returned from the method as a string.[[BR]] 
     203sum takes a variable number of integer args. 
    203204 
    204205 
     
    214215 
    215216== Example == 
     217 
     218{{{ 
     219class SimplestClass 
     220    pass 
     221 
     222class VeryMinimal 
     223    """ Docstring for class """ 
     224 
     225    cue init   
     226        base.init 
     227        # Above is equivalent to no initialiser at all 
     228        # .... rest of initialiser code 
     229 
     230    def aMethod 
     231        print 'in aMethod of class [this]' 
     232        # more method code 
     233}}} 
     234 
     235A more extended example. 
     236 
    216237{{{ 
    217238#Interfaces  
     
    253274        #_lifespan = 8   
    254275         
    255     def init 
     276    cue init 
    256277        _age = 1 
    257278        .liveWeight = 2