static void Main(string[] args) { //***** DUCKS Duck mallard = new MallardDuck(); mallard.performQuack(); mallard.performFly(); mallard.display(); mallard.setQuackBehaviour(new Squek()); mallard.performQuack(); Duck model = new ModelDuck(); model.performQuack(); model.display(); model.setFlyBehavior(new FlyRocketPowered()); model.performFly(); Console.ReadKey(); //***** CHOCOLATE FACTORY /* * ChocolateBoiler CB = ChocolateBoiler.getInstance(); * CB.fill(); * CB.boil(); * * Console.WriteLine("Hello World! Is the chocolate factory boiled? "+ CB.isBoiled()); * Console.ReadKey(); */ }
static void Main(string[] args) { //向上转型 //Duck mallard = new MallardDuck(); //mallard.performQuack(); //mallard.performFly(); Duck model = new ModelDuck(); model.performFly(); model.setFlyBehavior(new FlyRocketPowered()); model.performFly(); }
public static void Test() { Duck mallard = new MallardDuck(); mallard.performQuack(); mallard.performFly(); Duck model = new ModelDuck(); model.performFly(); model.setFlyBehavior(new FlyRocketPowered()); model.performFly(); }