Wiki

Changes between Version 3 and Version 4 of Property

Show
Ignore:
Timestamp:
05/07/12 06:40:06 (6 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Property

    v3 v4  
    33They are accessed using the same syntax as fields but do not designate storage locations.[[BR]] 
    44Instead, properties have accessors that read, write, or compute their values.[[BR]] 
    5 Values can be reflected directly (or indirectly (filtered)) in or out of a backing variable or computed, Its entirely up to the accessor. 
     5Values can be reflected directly (or indirectly (filtered)) in or out of a backing variable or computed, It's entirely up to the accessor. 
    66 
    77There are 3 keywords for defining a property:[[BR]] 
     
    2222{{{ 
    2323#!cobra 
    24 var _nLife  = 47       # protected access 
     24var _nLife  = 47       # backing variable with (implicit) protected access 
    2525pro nLife from var     # property nLife uses backing var _nLife 
    26 # above same as  
     26# above line same as  
    2727pro nLife  from _nLife 
    28 # but can use a different backing variable name from property name 
     28# but can use a different backing variable name from the property name 
    2929pro numLife from _nLife 
    3030 
    31 # or use a backing variable with different (shortcutted) accessability 
     31# or use a backing variable with different (also shortcutted) accessability 
    3232var __nLife0 = 48   # private access 
    3333 
     34pro nLife0 from var # use protected or private backing variable of same name 
     35#or alternatively property and backing variable explicitly named 
    3436pro nLife from __nLife0 
    3537}}} 
    3638 
    37 Can implicitly create (a protected) initialised backing variable and property in one line like 
     39You can implicitly create (a protected) initialised backing variable and property in one line like 
    3840{{{ 
    3941#!cobra 
     
    4244# or explicitly specifying type and initial value 
    4345pro nLife from var as int = 47 
     46 
     47# More commonly perhaps a set or get variant can be given in the same manner 
     48## (assume above prop dcls not made, any one of below is also valid) 
     49get nLife from var 
     50get nlifeSource from nLife 
     51 
     52set nLife from var   # name same as backing variable 
     53set nLifeSink from nlife  # any name same or unrelated to backing variable 
    4454}}} 
    4555 
    4656Finally if an accessor needs to translate, filter or modify in some way a backing variable or provide a virtual variable (computed)[[BR]] 
    4757there is a longer syntax variant where either of both the '''get''' and '''set''' accessors can be specified with a block of code to[[BR]] 
    48 store (setter) or generate (getter) the property value.  
     58store (setter) or generate (getter) the property value. 
     59 
     60Within the setter code block in such a variant an implicit parameter (of the same type as the property) named '''value'''[[BR]] 
     61is provided that has the value passed or assigned to the property.  
    4962 
    5063{{{ 
     
    5770        return 70 - _seed 
    5871   set 
     72        # implicit parameter 'value' contains the value given to set into the property  
    5973        require value >0 and value <65 
    6074        _seed = value 
    6175}}} 
    6276 
    63 Properties can have Attributes and the default [wiki:accessModifiers access modifiers] can be overridden explicitly if desired. 
     77Properties can have Attributes and the default [wiki:AccessModifiers access modifiers] can be overridden explicitly if desired. 
    6478 
    6579!DocStrings describing the property are both allowed and encouraged.