Skip to content

Instantly share code, notes, and snippets.

@GavinRay97
Created May 14, 2021 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GavinRay97/91f248c73fb0fd8f248d56bc047d0936 to your computer and use it in GitHub Desktop.
Save GavinRay97/91f248c73fb0fd8f248d56bc047d0936 to your computer and use it in GitHub Desktop.
D-lang Multiple Inheritance mimickry
import std.stdio;
interface Abstract1 {
void overrideMe1();
void sayHello();
mixin template Abstract1Impl() {
void sayHello() { import std.stdio; writeln("Hello"); }
}
}
interface Abstract2 {
void overrideMe2();
void sayGoodbye();
mixin template Abstract2Impl() {
void sayGoodbye() { import std.stdio; writeln("Goodbye"); }
}
}
class MyClass : Abstract1, Abstract2 {
mixin Abstract1Impl;
mixin Abstract2Impl;
override void overrideMe1() { writeln("overrode 1"); }
override void overrideMe2() { writeln("overrode 2"); }
}
void main() {
auto it = new MyClass();
it.sayHello();
it.sayGoodbye();
it.overrideMe1();
it.overrideMe2();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment