Really nooB question - @property
Mike Parker via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jul 20 18:03:00 PDT 2014
On 7/21/2014 3:14 AM, 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
In addition to what others have pointed out, it's useful for read-only
values. You don't always want to allow clients to be able to set an
objects members.
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
More information about the Digitalmars-d-learn
mailing list