@property - take it behind the woodshed and shoot it?

Michael pr at m1xa.com
Sun Jan 27 06:32:51 PST 2013


I think that "property as contract for accessing to variable" is 
good point. Maybe we have lack proper terminology, but idea is 
good.
Also it is can be pointed as "property itself - is static 
contract to accessing variable".

>>class A{
>>    private int i;
>>    int foo{
>>        out out(result){assert(result<=0);}body{return i; }
>>        in(int v)in{assert(v<=0);}out{assert(foo<=0);}body{ i = 
>> v; }
>>    }
>>}
Unified:
class A
{
     private int i;

     int foo
     {
         out{assert(@value<=0);}body{return i; }
         in{assert(@value<=0);}body{ i = @value; }
     }
}

@value - in getter it's return value;
@value - in setter it's param value;
void type is not allowed.

In theory, property always have only one in/out parameter of same 
type and performs lightweight actions.



More information about the Digitalmars-d mailing list