Skip to content

Instantly share code, notes, and snippets.

@JesseKPhillips
Created February 22, 2014 02:46
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 JesseKPhillips/9147869 to your computer and use it in GitHub Desktop.
Save JesseKPhillips/9147869 to your computer and use it in GitHub Desktop.
Scala traits as D interface... maybe.
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