Created
February 22, 2014 02:46
-
-
Save JesseKPhillips/9147869 to your computer and use it in GitHub Desktop.
Scala traits as D interface... maybe.
This file contains hidden or 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 Flying { | |
@property string flyingMessage(); | |
final void fly() { | |
writeln(flyingMessage); | |
} | |
} | |
interface Swimming { | |
final void swim() { | |
writeln("I swim"); | |
} | |
} | |
interface Bird {} | |
class Penguin : Swimming, Bird {} | |
class Pigeon : Swimming, Flying, Bird { | |
override @property string flyingMessage() { | |
return "I'm a flyer"; | |
} | |
} | |
class Hawk : Flying, Swimming, Bird { | |
override @property string flyingMessage() { | |
return "I'm an excellent flyer"; | |
} | |
} | |
class FrigateBird : Flying, Bird { | |
override @property string flyingMessage() { | |
return "I'm a good flyer"; | |
} | |
} | |
void main() { | |
auto flyingBird = [cast(Flying) | |
new Pigeon, | |
new Hawk, | |
new FrigateBird]; | |
foreach(b; flyingBird) | |
b.fly(); | |
auto swimmingBird = [cast(Swimming) | |
new Pigeon, | |
new Hawk, | |
new Penguin]; | |
foreach(b; swimmingBird) | |
b.swim(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment