public void TestModelDuck()

        {
            HeadFirstDesignPatterns.Strategy.Duck.Duck ModelDuck = new ModelDuck();

            Assert.AreEqual("Quack", ModelDuck.PerformQuack());

            Assert.AreEqual("I can't fly.", ModelDuck.PerformFly());



            ModelDuck.FlyBehavoir = new FlyRocketPowered();

            Assert.AreEqual("I'm flying with a rocket!", ModelDuck.FlyBehavoir.Fly());

            Assert.AreEqual("I'm flying with a rocket!", ModelDuck.PerformFly());



            ModelDuck.QuackBehavior = new MuteQuack();

            Assert.AreEqual("<<silence>>", ModelDuck.QuackBehavior.Quacking());

            Assert.AreEqual("<<silence>>", ModelDuck.PerformQuack());
        }
Exemplo n.º 2
0
        private static void RunStrategyPattern()
        {
            Duck model = new ModelDuck();

            model.PerformFly();
            model.PerformQuack();
            model.SetFlyBehavior(new FlyRocketPowered());
            model.PerformFly();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

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

            Duck model = new ModelDuck();

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



            Console.ReadKey();

            // Go to http://aka.ms/dotnet-get-started-console to continue learning how to build a console app!
        }
        public void model_duck_can_quack()
        {
            Duck model = new ModelDuck();

            Assert.AreEqual("Quack", model.PerformQuack());
        }