public void StrategyTest() { // given var goby = "bus"; IGotStrategy goStrategy = null; switch (goby) { case "bus": goStrategy = new GoByBus(); break; case "train": default: goStrategy = new GoByTrain(); break; } var traveler = new Traveler("小明", goStrategy); // when var result = traveler.Travel("台北"); // then Assert.AreEqual("小明搭巴士去台北", result); }
public string Travel(string place, string goby) { IGotStrategy goStrategy = null; switch (goby) { case "bus": goStrategy = new GoByBus(); break; case "train": default: goStrategy = new GoByTrain(); break; } return(_name + goStrategy.Go(place)); }
public Traveler(string name, IGotStrategy goStrategy) { _name = name; _goStrategy = goStrategy; }