Last active
August 29, 2015 13:56
-
-
Save andrefreitas/9267754 to your computer and use it in GitHub Desktop.
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
| /** | |
| * Example of a strategy pattern | |
| * We implement different behaviours for a robot | |
| */ | |
| class Robot { | |
| Behaviour behaviour; | |
| Robot(this.behaviour); | |
| move() => print(behaviour.move()); | |
| } | |
| abstract class Behaviour { | |
| move(); | |
| } | |
| class AgressiveBehaviour implements Behaviour{ | |
| move() => 'Agressive Behaviour: if find another robot attack it'; | |
| } | |
| class DefensiveBehaviour implements Behaviour{ | |
| move() => 'Defensive Behaviour: if find another robot run from it'; | |
| } | |
| class NormalBehaviour implements Behaviour{ | |
| move() => 'Normal Behaviour: if find another robot ignore it'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment