Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Watcher     watcher1    = new Watcher("Watcher1");
            Watcher     watcher2    = new Watcher("Watcher2");
            Watcher     watcher3    = new Watcher("Watcher3");
            TrainingGuy trainingGuy = new TrainingGuy();

            trainingGuy.Subscribe(watcher1);
            trainingGuy.Subscribe(watcher2);
            trainingGuy.Subscribe(watcher3);
            WorkoutController fitnessInstructor = new WorkoutController();

            SwitchDownCommand switchDownCommand = (SwitchDownCommand)CommandFactory.Create(CommandFactory.commandList.SwitchDown, trainingGuy);
            SwitchUpCommand   switchUpCommand   = (SwitchUpCommand)CommandFactory.Create(CommandFactory.commandList.SwitchUp);

            switchUpCommand.SetTrainingGuy(trainingGuy);

            fitnessInstructor.SetCommand(switchUpCommand);
            fitnessInstructor.ExecuteCommand();

            fitnessInstructor.SetCommand(switchDownCommand);
            fitnessInstructor.ExecuteCommand();

            fitnessInstructor.SetCommand(switchUpCommand);
            fitnessInstructor.ExecuteCommand();
        }
Exemplo n.º 2
0
 public static ICommand Create(commandList commandName, TrainingGuy trainingGuy)
 {
     if (commandName == commandList.SwitchUp)
     {
         return(new SwitchUpCommand(trainingGuy));
     }
     else if (commandName == commandList.SwitchDown)
     {
         return(new SwitchDownCommand(trainingGuy));
     }
     else
     {
         Console.WriteLine("Invalid command");
         return(null);
     }
 }
Exemplo n.º 3
0
 public SwitchDownCommand(TrainingGuy trainingGuy)
 {
     this.trainingGuy = trainingGuy;
 }
Exemplo n.º 4
0
 public void SetTrainingGuy(TrainingGuy trainingGuy)
 {
     this.trainingGuy = trainingGuy;
 }