DIP4: Properties
BLS
windevguy at hotmail.de
Sun Jul 26 15:33:36 PDT 2009
Michiel Helvensteijn wrote:
> BLS wrote:
>
>>> A one liner should do the trick too.
>>> [public] [const] property int i;
>> I am a little bit ''' about the feedback :
>> Is there really nobody who got it :
>
> I think people got it. But it's not a property. Your one-liner seems to be
> equivalent to a field. Except, I guess, that you can't take the address.
>
> The whole idea of a property is that it can have non-trivial getter/setter
> functions. Like a read-only property of a Line, that returns its length
> automatically calculated from its two points. Or a getter and setter that
> keep a log of all accesses to the information.
>
> My favorite example is of a Color class, that internally stores its value in
> the RGB model, but has properties to read and change its value through the
> HSV and HSL models as well.
>
well, the one liner assumes that the compiler will do code generation.
(maybe I should figure that out...
imutable property uint theAnswer = 42:
======================================
ie.
class universe
{
inmutable property uint theAnswer = 42:
/* expands to !!
pure uint get_theAnswer() nothrow()
{
return theAnswer;
}
private inmutable int theAnswer = 42
*/
}
and :
property bool has_cojones;
==========================
class manorweeny
{
property bool has_cojones;
/* expands to !!
bool get_has_cojones()
{
return has_cojones;
}
void set_has_Cojones(bool yep)
{
has_cjojones = yep;
}
private bool has_cojones = false;
*/
}
---- I just can imagine two property situations :
Read + Write OR Read Only...
thanks for you feedback Michiel,
Björn
More information about the Digitalmars-d
mailing list