Interesting Research Paper on Constructors in OO Languages
Craig Dillabaugh
cdillaba at cg.scs.careton.ca
Tue Jul 16 06:34:59 PDT 2013
On Tuesday, 16 July 2013 at 09:47:35 UTC, Regan Heath wrote:
clip
>
> We have class invariants.. these define the things which must
> be initialised to reach a valid state. If we had compiler
> recognisable properties as well, then we could have an
> initialise construct like..
>
> class Foo
> {
> string name;
> int age;
>
> invariant
> {
> assert(name != null);
> assert(age > 0);
> }
>
> property string Name...
> property int Age...
> }
>
> void main()
> {
> Foo f = new Foo() {
> Name = "test", // calls property Name setter
> Age = 12 // calls property Age setter
> };
> }
>
> The compiler could statically verify that the variables tested
> in the invariant (name, age) were set (by setter properies)
> inside the initialise construct {} following the new Foo().
>
> R
How do you envision this working where Name or Age must be set to
a value not known at compile time?
More information about the Digitalmars-d
mailing list