I'd like to use a mixin to implement an interface. This works fine until I subclass. The problem is that the mixin template also implement an template function.
Something like:
interface Features {
void feature1();
void feature2();
}
mixin template FeaturesImplementer() {
int bar;
final void feature1(){}
void feature2(){}
void typeStuff(T)(){}
}
class WithFeature: Features {
mixin FeaturesImplementer;
this(){typeStuff!(typeof(this));}
}
class AlsoWithFeature: WithFeature {
mixin FeaturesImplementer;
this(){typeStuff!(typeof(this));}
}
void main() {
new WithFeature;
new AlsoWithFeature;
}
outputs:
Error: function AlsoWithFeature.FeaturesImplementer!().feature1 cannot override final function WithFeature.FeaturesImplementer!().feature1
Deprecation: implicitly overriding base class method WithFeature.FeaturesImplementer!().feature2 with AlsoWithFeature.FeaturesImplementer!().feature2 deprecated; add 'override' attribute
Error: mixin AlsoWithFeature.FeaturesImplementer!() error instantiating
I could put typeStuff in another template but the problem is that in FeaturesImplementer everything goes together. Even the integer is used by the features. Is there a way to always use the same mixin with everuthing inside ?
this, if not remixed, this is always of the same type where the template has been mixed. - user5573432