Wiki

Changes between Version 2 and Version 3 of Property

Show
Ignore:
Timestamp:
11/28/10 11:37:01 (14 years ago)
Author:
hopscc
Comment:

corrections for clause order and implicit backing store creation

Legend:

Unmodified
Added
Removed
Modified
  • Property

    v2 v3  
    3232var __nLife0 = 48   # private access 
    3333 
    34 pro nLife from __nLife 
    35 }}} 
    36  
    37 Can implicitly create initialised backing variable and property in one line like 
    38 {{{ 
    39 #!cobra 
    40 pro nLife = 47 
     34pro nLife from __nLife0 
     35}}} 
     36 
     37Can implicitly create (a protected) initialised backing variable and property in one line like 
     38{{{ 
     39#!cobra 
     40pro nLife from var = 47  # type inferred from initial value 
     41 
     42# or explicitly specifying type and initial value 
     43pro nLife from var as int = 47 
    4144}}} 
    4245 
     
    4447there is a longer syntax variant where either of both the '''get''' and '''set''' accessors can be specified with a block of code to[[BR]] 
    4548store (setter) or generate (getter) the property value.  
     49 
     50{{{ 
     51#!cobra 
     52var _seed = 21 
     53 
     54# a calculated property 
     55pro nLife  
     56   get 
     57        return 70 - _seed 
     58   set 
     59        require value >0 and value <65 
     60        _seed = value 
     61}}} 
    4662 
    4763Properties can have Attributes and the default [wiki:accessModifiers access modifiers] can be overridden explicitly if desired. 
     
    5874 
    5975{{{ 
    60 get <propName> [as <Type>] [from {var, <backingVariableName>} [= <initValue>] ]  
    61     [has <AttributeList>]  
    62     [is <accessModifier>] 
    63     [<DocString>] 
    64  
    65 set <propName> [as <Type>] [from {var, <backingVariableName>} [= <initValue>] ]  
    66     [has <AttributeList>]  
    67     [is <accessModifier>] 
    68     [<DocString>] 
    69  
    70 pro <propName> [as <Type>] [from {var, <backingVariableName>} [= <initValue>]]  
     76get <propName> [from {var, <backingVariableName>} [as <Type>] [= <initValue>] ]  
     77    [has <AttributeList>]  
     78    [is <accessModifier>] 
     79    [<DocString>] 
     80 
     81set <propName> [from {var, <backingVariableName>} [as <Type>] [= <initValue>] ]  
     82    [has <AttributeList>]  
     83    [is <accessModifier>] 
     84    [<DocString>] 
     85 
     86pro <propName> [from {var, <backingVariableName>} [as <Type>] [= <initValue>]]  
    7187    [has <AttributeList>]  
    7288    [is <accessModifier>]