Created
October 26, 2012 13:35
-
-
Save back2dos/3958864 to your computer and use it in GitHub Desktop.
Example of partial implementations
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
| 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); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome thanks!