Exemple #1
0
        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();
    }
Exemple #3
0
        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();
             */
        }
Exemple #4
0
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

            mallard.performFly();
            mallard.performQuack();

            Duck model = new ModelDuck();

            model.performFly();
            // Dynamically update a class at runtime
            model.FlyBehavior = new FlyRocketPowered();
            model.performFly();

            DuckCall duckCall = new DuckCall();

            duckCall.performQuack();
        }
        static void Main(string[] args)
        {
            var mallardDuck = new MallardDuck();

            mallardDuck.display();
            mallardDuck.performQuack();
            mallardDuck.performFly();

            var RubberDuck = new RubberDucky();

            RubberDuck.performFly();
            RubberDuck.display();
            RubberDuck.performQuack();

            WriteLine("______________________");
            Duck model = new ModelDuck();

            model.performFly();
            model.flyBehavior = new FlyRocketPowered();
            model.performFly();
        }
Exemple #6
0
    public static void Main(string[] args)
    {
        var f    = new FlyWithWings();
        var q    = new Squeak();
        var duck = new ModelDuck(f, q);

        duck.performFly();
        duck.display();
        duck.performQuack();
        //Your code goes here
        Console.WriteLine("Hello, world!");
    }
Exemple #7
0
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

            mallard.Display();
            mallard.performQuack();
            mallard.performFly();


            Duck model = new ModelDuck();

            model.Display();
            model.performFly();
            model.SetFlyBehavior(new FlyRocketPowered());
            model.performFly();

            Console.WriteLine("The following is a duck call");
            DuckCall duckCall = new DuckCall(new RegularQuack());

            duckCall.Quack();

            Console.ReadLine();
        }