I like the possibility of abandoning () in function calls in D, so we can firstly make attribute public and then if implementation changes, smoothly change it into function:

call:
<code>
auto a = new A();
writeln("Size is " +a.size);
auto b = new B();
writeln("Size is " +b.size);

class A {
    public int size = 0;
}

class B {
    public int size() { return 0; }
}
</code>

Although, if I'd like to make interface Sizeable, it's impossible to treat attribute and method equally:
<code>
interface Sizeable {
/*
int size; // Error: variable Sizeable.size field not allowed in interface
    int size(); //
*/
class A : Sizeable {
    public int size = 0; // Error: Does not implements int size()
}

class B : Sizeable {
    public int size() { return 0; }
}
</code>

Is it possible to make it work?

Best regards,
Mariusz Gliwiński

Reply via email to