Really nooB question - @property
John Colvin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 21 04:26:00 PDT 2014
On Sunday, 20 July 2014 at 18:14:29 UTC, Eric wrote:
>
>> Use @property when you want a pseudo-variable or something
>> that might be conceptually considered a "property" of the
>> object, i.e. to do this:
>>
>> auto blah = thing.someProperty;
>> thing.someProperty = blahblah;
>>
>
> This is basically what I suspected. But why
> write:
>
> @property int getValue() { return(value); }
>
> When you could just have a public field:
>
> int value;
>
> That lets you set and get the value without the parens anyways?
>
> thanks,
>
> Eric
It allows you to add extra logic on read/write, without breaking
any user code.
More information about the Digitalmars-d-learn
mailing list