Build interface from abstract class

DigitalDesigns DigitalDesigns at gmail.com
Mon May 28 09:59:50 UTC 2018


Implementing interfaces can be a pain but are necessary.

I like to use abstract classes and provide a base implementation. 
It would be cool if I could use D's awesome meta features to 
extract the interface from the abstract class then build it. This 
requires some funky stuff which I'm not sure D can do

mixin(InterfaceFromAbstractClass!(MyAbstraction, "MyInterface"));

interface MyInterface2 : MyInterface
{
     final static void baz() { }
}

abstract class MyAbstraction : MyInterface2
{
     @InterfaceMembers
     {
         void foo() { };
     }
}

InterfaceFromAbstractClass will get all the @InterfaceMembers 
members and declare them in an interface MyInterface.

This avoids all the duplicate code that interfaces has to create.

Is this possible in D?




More information about the Digitalmars-d-learn mailing list