Feedback on Átila's Vision for D

Max Samukha maxsamukha at gmail.com
Sun Oct 20 09:25:14 UTC 2019


On Saturday, 19 October 2019 at 23:09:11 UTC, Meta wrote:
> void main()
> {
>     Display dsp = new Test();
>     Debug dbg = new Test();
>     dsp.fmt();
>     dbg.fmt();
> }

You can't do that if the interfaces come from third parties. 
There is a half-working hack using nested classes, but it is 
obviously inadequate:

interface A {
     void foo();
}

interface B {
     void foo();
}

class C: A {
     private final class _B: B {
         override void foo() {
             this.outer.bFoo();
         }
     }

     private _B _b;
     final B b() {
         return _b;
     }
     alias b this;

     this() {
         _b = new _B();
     }

     import std.stdio;
     override void foo() {
         writeln("A.foo");
     }

     void bFoo() {
         writeln("B.foo");
     }
}


class D: C {
}

void main() {
     auto c = new C;
     // auto c = new D; // won't work because of broken 'alias 
this'
     A a = c;
     B b = c;

     a.foo(); // "A.foo"
     b.foo(); // "B.foo"
}




More information about the Digitalmars-d mailing list