コード例 #1
0
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

            mallard.Display();
            mallard.PerformFly();
            mallard.PerformQuack();

            Duck model = new ModelDuck();

            model.Display();
            model.PerformFly();
            model.PerformQuack();
            model.FlyBehavior = new FlyRocketPowered();
            model.PerformFly();

            Console.ReadKey();

            #region 2021-05-10 20:04
            //I'm a real Mallard duck.
            //I'm flying!!
            //Quack
            //I'm a model duck.
            //I can't fly.
            //Quack
            //I'm flying with a rocket!
            #endregion
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Duck mallardDuck  = new MallardDuck();
            Duck readheadduck = new ReadheadDuck();
            Duck rubberDuck   = new RubberDuck();
            Duck decoyDuck    = new DecoyDuck();
            Duck modelDuck    = new ModelDuck();

            mallardDuck.Display();
            mallardDuck.PerformQuack();
            mallardDuck.PerformFly();

            readheadduck.Display();
            readheadduck.PerformQuack();
            readheadduck.PerformFly();

            rubberDuck.Display();
            rubberDuck.PerformQuack();
            rubberDuck.PerformFly();

            decoyDuck.Display();
            decoyDuck.PerformQuack();
            decoyDuck.PerformFly();

            modelDuck.Display();
            modelDuck.PerformFly();
            modelDuck.FlyBehavior = new FlyRocketPowered();
            modelDuck.PerformFly();

            Console.ReadKey();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

            mallard.PerformQuack();
            mallard.PerformFly();

            Duck model = new ModelDuck();

            model.PerformFly();
            model.FlyBehavior = new FlyRocketPowered();
            model.PerformFly();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

            mallard.PerformQuack();
            mallard.PerformFly();
            Console.WriteLine("----------");

            Duck modelDuck = new ModelDuck();

            modelDuck.PerformFly();
            modelDuck.setFly(new FlyRocket());
            modelDuck.PerformQuack();
        }
コード例 #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("-> Testing different ducks behaviors.");
            var mallard = new MallardDuck();

            mallard.Display();
            mallard.PerformQuack();
            mallard.PerformFly();

            var redhead = new RedheadDuck();

            redhead.Display();
            redhead.PerformQuack();
            redhead.PerformFly();

            var rubber = new RubberDuck();

            rubber.Display();
            rubber.PerformQuack();
            rubber.PerformFly();

            var decoy = new DuckDecoy();

            decoy.Display();
            decoy.PerformQuack();
            decoy.PerformFly();

            Console.WriteLine();
            Console.WriteLine("-> Test runtime behavior change.");
            var model = new ModelDuck();

            model.Display();
            model.PerformQuack();
            model.PerformFly();

            model.FlyBehavior = new FlyRocketPowered();
            Console.WriteLine("Fly behavior of ModelDuck was changed and now it's...");
            model.PerformFly();

            Console.WriteLine();
            Console.WriteLine("-> Class not in duck hierarchy using duck behavior.");
            var soundSynthesizer = new SoundSynthesizer();

            soundSynthesizer.DuckSound();

            Console.WriteLine();
            Console.WriteLine("Press any key to continue. . .");
            Console.ReadKey();
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: dougallison/hfdp
        private static void Main(string[] args)
        {
            var mallard = new MallardDuck();

            mallard.PerformQuack();
            mallard.PerformFly();

            Console.WriteLine();

            var model = new ModelDuck();

            model.PerformFly();
            model.FlyBehavior = new FlyRocketPowered();
            model.PerformFly();
        }
コード例 #7
0
        static void Main(string[] args)
        {
            Duck mallardDuck = new MallardDuck();

            mallardDuck.PerformQuack();
            mallardDuck.PerformFly();

            Duck modelDuck = new ModelDuck();

            modelDuck.PerformFly();
            modelDuck.SetFlyBehaviour(new FlyRemoteControl());
            modelDuck.PerformFly();

            Console.ReadKey();
        }
コード例 #8
0
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

            mallard.Display();
            mallard.PerformQuack();
            mallard.PerformFly();

            Duck model = new ModelDuck();

            model.PerformFly();
            model.SetFlyBehavior(new FlyRocketPowered());
            model.PerformFly();

            Console.ReadKey();
        }