static void Main(string[] args) { TravelStrategy train = new TrainStrategy(); TravelContext context = new TravelContext("广州", "上海"); context.SetStrategy(train); context.TravelFuction(); TravelStrategy air = new AirStrategy(); context.SetStrategy(air); context.TravelFuction(); TravelContext context2 = new TravelContext2("广州", "上海", "最快"); TravelStrategy walk = new WalkfastStrategy(); context2.SetStrategy(walk); context2.TravelFuction(); Console.ReadKey(); }
public void Travel(TravelContext t) { TravelContext2 t2 = (TravelContext2)t; Console.WriteLine("从" + t2.Start + "到" + t2.End + t2.Way + "的步行方案"); }