Wiki
Show
Ignore:
Timestamp:
03/20/10 04:42:28 (2 years ago)
Author:
Chuck.Esterbrook
Message:

Improvements to the How-To's.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/HowTo/111-UseProperties.cobra

    r2127 r2335  
    4444 
    4545# Many properties just cover for an underlying variable. When that 
    46 # is the case, you can use a shortcut syntaxes. Later, you can 
     46# is the case, you can use a shortcut syntax. Later, you can 
    4747# change the property to the full form in order to add logic. 
    4848 
     
    6161 
    6262 
     63# You can even pack an initial value into the declaration 
     64# which also be used to infer the data type. 
     65 
     66class Person3 
     67 
     68    pro name from var = ''  # inferred as String 
     69     
     70    pro age from var = 0    # inferred as int 
     71 
     72 
    6373# In this shortcut syntax, the vars were already declared so 
    6474# the property simply "... from var": 
    6575 
    66 class Person3 
     76class Person4 
    6777 
    6878    var _name as String 
     
    8898# you can specify that name instead of "var": 
    8999 
    90 class Person4 
     100class Person5 
    91101 
    92102    var _name as String 
     
    101111# Properties can be read-only: 
    102112 
    103 class Person5 
     113class Person6 
    104114 
    105115    cue init(name as String)