andrefreitas
2/28/2014 - 9:05 AM

gistfile1.dart

/**
 * 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';
}