Skip to content

Instantly share code, notes, and snippets.

@andrefreitas
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save andrefreitas/9267754 to your computer and use it in GitHub Desktop.

Select an option

Save andrefreitas/9267754 to your computer and use it in GitHub Desktop.
/**
* 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