Wiki

Changes between Version 11 and Version 12 of Classes

Show
Ignore:
Timestamp:
05/16/10 12:58:30 (14 years ago)
Author:
hopscc
Comment:

expand Properties, cleanup

Legend:

Unmodified
Added
Removed
Modified
  • Classes

    v11 v12  
    109109 
    110110== Properties == 
    111 Define a property for the class 
    112  
    113 ''To be expanded'' 
    114  
    115 === Properties Grammar === 
    116  
    117 {{{ 
    118 get <propName> [ as {<Type>, var}] [is <accessModifier>] 
    119 set <propName> [ as {<Type>, var}   [is <accessModifier>] 
    120  
    121 pro <propName> [ as {<Type>, var}] [is <accessModifier>] 
    122  
    123 pro <propName> [is <accessModifier>] 
    124  
     111''This discussion is somewhat simplified for clarity.[[BR]] 
     112Please see 
     113[wiki:Property Properties]'' 
     114 
     115Properties are members that provide a flexible mechanism to read, write, or compute the values of private fields. [[BR]] 
     116They  are used as if they are public data members, but are actually implemented via special methods called accessors. 
     117 
     118There are 3 keywords for defining a property:[[BR]] 
     119'''get''' defines a readOnly property ( Can access the properties value but cant change it). [[BR]] 
     120'''set''' defines a writeOnly property (Can write to the property but cant read it)[[BR]] 
     121'''pro''' defines a readable and writable property. 
     122 
     123If a property accessor merely reflects a protected or private backing variable (field) you can[[BR]] 
     124use a clause beginning with keyword '''from'''. 
     125  *  '''from var''' [[BR]] 
     126    {{{ pro <name> from var }}} or {{{get <name> from var}}} or {{{ set <name> from var}}}[[BR]] 
     127    The property will get or set its value unchanged from a backing variable named  
     128    to the property name with a single underscore prepended to it.  
     129      * If there is no backing variable but there is an assignment to the property or a type declaration on the property 
     130        the backing variable will be implicitly created for you. 
     131  * ''' from <backingVarName>'''[[BR]] 
     132    Otherwise the word following the '''from''' must be the name of an existing backing store variable. 
     133 
     134Finally if an accessor needs to translate, filter or modifies in some way a backing variable or computes a value[[BR]] 
     135there is a longer syntax variant where either of both the get and set accessors can be specified and a block of code[[BR]]  
     136provided to store (setter) or generate (getter) the property value.  
     137 
     138=== (Simplified) Properties Grammar === 
     139 
     140{{{ 
     141get <propName> [ as <Type>] [from {var, <backingVariableName>} [= <initValue>] ] 
     142    [<DocString>] 
     143 
     144set <propName> [ as <Type>] [from {var, <backingVariableName>} [= <initValue>] ]  
     145    [<DocString>] 
     146 
     147pro <propName> [ as <Type>] [from {var, <backingVariableName>} [= <initValue>] ]  
     148    [<DocString>] 
     149 
     150# full accessor variant, one or both of 'get' and 'set blocks must be present. 
     151pro <propName>  
    125152    get  
    126153        [...] 
    127154        return <value> 
    128155    set 
    129         [...] # assign or otherwise do something with implicit arg "value" (passed in) to something  
    130  
    131 }}} 
     156        [...] # assign or otherwise do something with implicit arg "value" (passed in)  
     157 
     158}}} 
     159 
     160=== Property Example === 
     161{{{ 
     162var _x  = 47 
     163pro x from var     # property x uses backing var _x 
     164# above same as  
     165#pro x from _x 
     166}}} 
     167 
     168Can do all of the above in one line like 
     169{{{ 
     170pro x = 47 
     171# or 
     172pro x as int = 47 
     173}}} 
     174 
     175Above is equivalent to fully specified accessor form 
     176{{{ 
     177var _x = 47 
     178pro 
     179    get 
     180        return _x 
     181    set 
     182        _x = value 
     183 
     184}}} 
     185 
     186 
    132187 
    133188== Methods == 
     
    203258sum takes a variable number of integer args. 
    204259 
    205  
    206 == Generics == 
    207 +++TBD+++ Generics 
    208  
    209  
    210 ++accessing baseclass methods 
     260== TBD == 
     261 
     262''Generics'' 
     263 
     264''accessing baseclass methods'' 
    211265 
    212266