Beispiel #1
0
        private static void Main()
        {
            var mallard = new MallardDuck {
                Quacker = new QuackNormal()
            };

            mallard.Display();
            mallard.Flyer = new FlyWings();
            mallard.Display();
        }
Beispiel #2
0
        public void MiniDuckSimulator()
        {
            Duck mallard = new MallardDuck();

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

            Duck model = new ModelDuck();

            mallard.Display();
            mallard.PerformFly();
            model.SetFlyBehavior(new FlyRocketPowered());
            mallard.PerformQuack();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            // Pato Bravo
            MallardDuck md = new MallardDuck();

            md.Display();
            md.Swim();
            md.Fly();
            md.Quack();
            System.Console.WriteLine("\n");

            // Pato Cabeça-vermelha
            RedHeadDuck rhd = new RedHeadDuck();

            rhd.Display();
            rhd.Swim();
            rhd.Fly();
            rhd.Quack();
            System.Console.WriteLine("\n");

            // Pato de Borracha
            RubberDuck rd = new RubberDuck();

            rhd.Display();
            rhd.Swim();
            rd.Quack(); // Chia invés de grasnar
            System.Console.WriteLine("\n");

            Console.ReadKey();
        }
Beispiel #4
0
        private static void Main()
        {
            var mallardDuck = new MallardDuck();

            mallardDuck.Display();
            mallardDuck.PerformQuack();
            mallardDuck.Swim();
            mallardDuck.PerformFly();
            Console.WriteLine();

            var redheadDuck = new RedheadDuck();

            redheadDuck.Display();
            redheadDuck.PerformQuack();
            redheadDuck.Swim();
            redheadDuck.PerformFly();
            Console.WriteLine();

            var rubberDuck = new RubberDuck();

            rubberDuck.Display();
            rubberDuck.PerformQuack();
            rubberDuck.Swim();
            rubberDuck.PerformFly();
            Console.WriteLine();

            var decoyDuck = new DecoyDuck();

            decoyDuck.Display();
            decoyDuck.Swim();
            Console.WriteLine();

            Console.Write("Press Enter to exit ...");
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            // Pato Bravo
            MallardDuck md = new MallardDuck();
            md.Display();
            md.Swim();
            md.Fly();
            md.Quack();
            System.Console.WriteLine("\n");

            // Pato Cabeça-vermelha
            RedHeadDuck rhd = new RedHeadDuck();
            rhd.Display();
            rhd.Swim();
            rhd.Fly();
            rhd.Quack();
            System.Console.WriteLine("\n");

            // Pato de Borracha
            RubberDuck rd = new RubberDuck();
            rhd.Display();
            rhd.Swim();
            rd.Quack(); // Chia invés de grasnar
            System.Console.WriteLine("\n");

            Console.ReadKey();
        }
Beispiel #6
0
        public void TestMethod1()
        {
            IFlyBehaviour flyBehaviour = new FlyBehaviour();

            MallardDuck mallardDuck = new MallardDuck(flyBehaviour);
            RedheadDuck redheadDuck = new RedheadDuck(flyBehaviour);

            IFlyBehaviour noFlyBehaviour = new NoFlyBehaviour();
            RubberDuck    rubberDuck     = new RubberDuck(noFlyBehaviour);


            mallardDuck.Display();
            mallardDuck.Fly();

            redheadDuck.Display();
            redheadDuck.Fly();

            rubberDuck.Display();
            rubberDuck.Fly();

            rubberDuck.ChangeFlyBehaviour(flyBehaviour);
            rubberDuck.Fly();

            redheadDuck.Swim();
            mallardDuck.Swim();
            rubberDuck.Swim();
        }
Beispiel #7
0
        public void MarllardDuckTest()
        {
            var duck = new MallardDuck();

            duck.PerformFly();
            duck.PerformQuack();
            duck.Display();
        }
Beispiel #8
0
        public static void Test_1()
        {
            var mallardDuck = new MallardDuck();

            mallardDuck.Display();
            mallardDuck.PerformFly();
            mallardDuck.SetFlyBehavior(new FlyNoWay());
            mallardDuck.PerformFly();
            mallardDuck.PerformQuack();
            mallardDuck.SetFlyBehavior(new FlyLikeRocket());
            mallardDuck.PerformFly();
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Create Mallard Duck");
            Console.WriteLine();

            Duck duck = new MallardDuck();

            duck.Display();
            duck.PerformQuack();
            duck.PerformFly();
            duck.Swim();
            Console.WriteLine();

            Console.WriteLine("Change the state");
            Console.WriteLine();
            duck.SetFlyBehavior(new FlyRocketPowered());
            duck.SetQuackBehavior(new MuteQuack());
            duck.Display();
            duck.PerformQuack();
            duck.PerformFly();
            duck.Swim();
        }
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

            mallard.PerformQuack();
            mallard.PerformFly();
            mallard.Display();
            Console.WriteLine();
            Duck model = new ModelDuck();

            model.PerformFly();
            model.SetFlyBehavior(new FlyRocketPowered());
            model.PerformFly();
        }
        static void Main(string[] args)
        {
            var mallard = new MallardDuck();
            mallard.Display();
            mallard.PerformFly();
            mallard.PerformQuack();

            var modelDuck = new ModelDuck();
            modelDuck.PerformFly();
            modelDuck.SetFlyBehavior(new FlyRocketPowered());
            modelDuck.PerformFly();

            Console.ReadKey(true);
        }
        public void DuckSimulatorTest()
        {
            var mallardDuck = new MallardDuck(new FlyWithWings(), new Quack());

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

            //Dynamically change behavior
            mallardDuck.ChangeFlyBehaviour(new FlyRocketPower());
            mallardDuck.PerformFly();


            Assert.True(true);
        }
        static void Main(string[] args)
        {
            var mallard = new MallardDuck();
            mallard.PerformFly();
            mallard.PerformQuack();
            mallard.Display();
            mallard.Swim();

            var modelDuck = new ModelDuck();
            modelDuck.Display();
            modelDuck.PerformFly();
            modelDuck.FlyBehaviour = new FlyRocketPowered();
            modelDuck.PerformFly();
            Console.ReadLine();
        }
        public void Duck_Behaviors_CanChangeBehaviorAtRuntime()
        {
            Duck mallard = new MallardDuck();

            mallard.Display();

            Assert.AreEqual("Quack!", mallard.Quack());
            Assert.AreEqual("I can fly!", mallard.Fly());

            mallard.SetQuackBehavior(new MuteQuack());
            mallard.SetFlyBehavior(new FlyNoWay());

            Assert.AreEqual("<silence>", mallard.Quack());
            Assert.AreEqual("I can't fly", mallard.Fly());
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            Duck duck = new MallardDuck();

            duck.Display();
            duck.PerformFly();
            duck.PerformQuack();

            Duck model = new DecoyDuck();

            model.Display();
            model.PerformFly();
            model.SetFlyBehavior(new FlyWithWings());
            model.PerformFly();

            Console.ReadLine();
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            Duck duckMallard = new MallardDuck("José");
            Duck duckRedhead = new RedheadDuck("Jaum");
            Duck rubberDuck  = new RubberDuck("Pedro");

            duckMallard.Display();
            duckMallard.Quack();
            duckMallard.Swin();
            duckMallard.Fly();

            duckRedhead.Display();
            duckRedhead.Quack();
            duckRedhead.Swin();
            duckRedhead.Fly();

            rubberDuck.Display();
            rubberDuck.Quack();
            rubberDuck.Swin();
            rubberDuck.Fly();
        }
Beispiel #17
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;

                try
                {
                    DbInitializer.Initialize(services);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }

            FlyWithWings fly   = new FlyWithWings();
            FlyNoWay     noFly = new FlyNoWay();

            MallardDuck md         = new MallardDuck(fly);
            RedheadDuck red        = new RedheadDuck(fly);
            RubberDuck  rubberDuck = new RubberDuck(noFly);

            md.Display();
            md.Fly();

            red.Display();
            red.Fly();

            rubberDuck.Display();
            rubberDuck.Fly();



            host.Run();
        }
Beispiel #18
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();
        }
Beispiel #19
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    //var context = services.GetRequiredService<AnimalCrossingContext>();
                    DbInitialiser.Initialize(services);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            FlyWithWing fly   = new FlyWithWing();
            FlyNoWay    noFly = new FlyNoWay();

            MallardDuck md  = new MallardDuck(fly);
            RedHeadDuck red = new RedHeadDuck(fly);
            RubberDuck  rd  = new RubberDuck(noFly);

            md.Display();
            md.Fly();

            red.Display();
            red.Fly();

            rd.Display();
            rd.Fly();

            host.Run();
        }
Beispiel #20
0
        static void Main(string[] args)
        {
            Console.WriteLine("##### 例子1 #####");

            // 无折扣.
            DiscountContext c1 = new DiscountContext(new NoDiscountStrategy());
            // 每本1元.
            DiscountContext c2 = new DiscountContext(new FlatRateStrategy()
            {
                OneCopyDiscount = 1
            });
            // 总金额 10%
            DiscountContext c3 = new DiscountContext(new PercentageStrategy()
            {
                Percent = 0.1M
            });

            Console.WriteLine(c1.GetBookDiscount(100, 10));
            Console.WriteLine(c2.GetBookDiscount(100, 10));
            Console.WriteLine(c3.GetBookDiscount(100, 10));



            Console.WriteLine("##### 例子2 #####");

            MallardDuck mallardDuck = new MallardDuck();
            RedheadDuck redheadDuck = new RedheadDuck();
            RubberDuck  rubberDuck  = new RubberDuck();

            Console.WriteLine(mallardDuck.Display() + " # " + mallardDuck.PerformFly().ToString() + " # " + mallardDuck.PerformQuack().ToString());
            Console.WriteLine(redheadDuck.Display() + " # " + redheadDuck.PerformFly().ToString() + " # " + redheadDuck.PerformQuack().ToString());
            Console.WriteLine(rubberDuck.Display() + " # " + rubberDuck.PerformFly().ToString() + " # " + rubberDuck.PerformQuack().ToString());



            Console.ReadLine();
        }
        public void duck_is_a_mallard_duck()
        {
            Duck mallard = new MallardDuck();

            Assert.AreEqual("I'm a Mallard Duck.", mallard.Display());
        }
Beispiel #22
0
        static void Main(string[] args)
        {
            var md = new MallardDuck();

            Console.WriteLine(md.Display() + "#" + md.Swim() + "#" + md.FlyBehavior.Fly() + "#" + md.QuackBehavior.Quack());
        }