Skip to content

Instantly share code, notes, and snippets.

@back2dos
Created October 26, 2012 13:35
Show Gist options
  • Select an option

  • Save back2dos/3958864 to your computer and use it in GitHub Desktop.

Select an option

Save back2dos/3958864 to your computer and use it in GitHub Desktop.
Example of partial implementations
package ;
import tink.lang.Cls;
class Main {
static function main() {
var foods = 'cookie,soup,banana'.split(',');
var eaters = [new Human(), new CookieMonster(), new Robot()];
for (e in eaters)
for (f in foods)
e.eat(f);
$type(eaters);// Array<Mouth>
}
}
interface Mouth implements Cls {
public function eat(food:String):Void {
trace('Yummy, what a delicious ' + food);
}
}
interface SweetTooth implements Mouth {
public function eat(food:String):Void {
if (food == 'cookie') trace('Cookiiiiieeee!!!!');
else trace('ewwww!!!');
}
}
class Human implements Mouth {
public function new() {}
}
class CookieMonster implements SweetTooth {
public function new() {}
}
class Robot implements Mouth {
public function new() {}
public function eat(food:String):Void {
trace('Robots do not eat ' + food);
}
}
@MondayPM

Copy link
Copy Markdown

Awesome thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment