Created
May 14, 2021 21:20
-
-
Save GavinRay97/91f248c73fb0fd8f248d56bc047d0936 to your computer and use it in GitHub Desktop.
D-lang Multiple Inheritance mimickry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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