Interface inheritance simplification
JS
js.mdnq at gmail.com
Sat Jul 13 19:10:48 PDT 2013
It would be nice if this is possible:
interface A // : gets inserted by the mixin
{
mixin sometemplate!B; // Is able to make A extend B
}
or
interface A : mixin sometemplate!B
{
// methods get inserted by the template
}
instead of
interface A : B
{
mixin sometemplate!B;
}
which locks A to B.
One, I imagine can easily accomplish the same task with mixins
and static if's but it requires writing code in two places.
e.g.,
interface A : mixin somtemplateA!B
{
mixin sometemplateB!B;
}
The point is to simplify boilerplate code... e.g., write
interfaces and templates that automatically write default methods
for you.
I think ideally something like the 2nd example would work best:
interface A : mixin sometemplate!B { }
so that we know A herits B but the template is able to insert
methods into the body of the interface WITHOUT having to manually
call another mixin to do so.
One can sort of achieve this with a mixin but it's not a good
way. e.g.,
interface A : mixin("B { void method(); ")
}
I *think* will work but the correct syntax is hidden...
More information about the Digitalmars-d-learn
mailing list