Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
 public Traveler(string name, IGotStrategy goStrategy)
 {
     _name       = name;
     _goStrategy = goStrategy;
 }