DIP26: properties defined
Michel Fortin
michel.fortin at michelf.ca
Fri Feb 8 19:13:45 PST 2013
On 2013-02-08 23:53:30 +0000, Robert <jfanatiker at gmx.at> said:
> Ok. Here finally it is:
>
> http://wiki.dlang.org/DIP26
This is pretty much exactly how I think properties should work. There's
two possible benefits you may to have overlooked…
One benefit of the "@property T foo;" syntax that does the boilerplate
code for you over using a plain variable: the getter and setter
generated are virtual in a class, so a derived class can override them.
Doesn't work with a plain variable.
Another possible benefit that we could have is the ability to use the
default getter but to provide your own setter implementation by just
declaring it:
@property int a;
@property void a(int value) { __a = value; refresh(); }
Much cleaner than this:
private int _a;
@property int a() { return _a; }
@property void a(int value) { _a = value; refresh(); }
It's really great to not have to write boilerplate functions when
default behaviour is perfectly fine. I've been using Objective-C for a
while now and the recent changes where it automatically synthesize a
variable, a getter, and a setter when declaring a property (unless you
provide your own) are truly delightful.
--
Michel Fortin
michel.fortin at michelf.ca
http://michelf.ca/
More information about the Digitalmars-d
mailing list