Properties

Miles _______ at _______.____
Thu Jan 8 16:59:38 PST 2009


Nick Sabalausky wrote:
> A property setter is ALWAYS going to return nothing and

Both the getter and the setter should return an rvalue. Properties exist
so that they are interchangeable with real member variables. Something
that is possible with member variables MUST also be possible with
properties, in a transparent way for any code outside the class.

For example:

	button.width = button.height = 50;	// makes a square button

Optimally, this should expand to either:

	button._set_width(button._set_height(50));

or

	button._set_height(50);
	button._set_width(button._get_height());

>From the compiler point-of-view, the first is easier to implement.

> take in exactly one argument, of the same type as the property,
> and that value will ALWAYS represent the intended new value.

Also not true. It is fine to have method polymorphism for the setter.
You may want to define property set(int value), set(Bigint value) and
set(float value), all with different semantics.



More information about the Digitalmars-d mailing list