Example #1
0
        static void Main()
        {
            Duck littleDuck = new RubberDuck();
            Duck woodenDuck = new WoodenDuck();
            Duck simleDuck  = new SimpleDuck();
            Duck fakeDuck   = new FakeDuck();

            Console.WriteLine("1st duck");
            littleDuck.PerformFly();
            littleDuck.PerformQuack();
            littleDuck.Swim();

            Console.WriteLine("\n");

            Console.WriteLine("2nd duck");
            woodenDuck.PerformFly();
            woodenDuck.PerformQuack();
            woodenDuck.Swim();

            Console.WriteLine("\n");

            Console.WriteLine("3rd duck");
            simleDuck.PerformFly();
            simleDuck.PerformQuack();
            simleDuck.Swim();

            Console.WriteLine("\n");

            Console.WriteLine("4th duck");
            fakeDuck.PerformFly();
            fakeDuck.PerformQuack();
            fakeDuck.Swim();

            Console.ReadKey();
        }
Example #2
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();
        }
Example #3
0
        static void Main(string[] args)
        {
            Duck duck = new MallardDuck();

            PrintMsg(duck);
            sb.AppendLine();


            duck = new RedHeadDuck();
            duck.SetFlyBehavior(Delegation.New <FlyBehavior>(typeof(NoVoice)));
            duck.SetQuackBehavior(new QuackBehavior(typeof(Squeak)));
            PrintMsg(duck);
            sb.AppendLine();

            duck = new RedHeadDuck();
            duck.SetQuackBehavior(new QuackBehavior(typeof(NoVoice)));
            PrintMsg(duck);
            sb.AppendLine();

            duck = new RubberDuck();
            duck.SetFlyBehavior(Delegation.New <FlyBehavior>(typeof(FlyNoWay)));           //new FlyBehavior(typeof(FlyNoWay))
            duck.SetQuackBehavior(new QuackBehavior(typeof(MuteQuack)));
            PrintMsg(duck);
            sb.Append(duck.Swim());
            sb.AppendLine();

            Console.WriteLine(sb.ToString());
            Console.ReadLine();
        }
Example #4
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();
        }
        public void RubberDuck_Should_Quack_Swim_Display()
        {
            var rubberDuck = new RubberDuck();

            Assert.Equal("squeak", rubberDuck.PerformQuack());
            Assert.Equal("swim", rubberDuck.Swim());
            Assert.Equal("looks like a rubberduck", rubberDuck.Display());
        }
Example #6
0
        public void CheckRubberDuck()
        {
            var wd = new RubberDuck();

            wd.Show();
            wd.Fly();
            wd.Quack();
            wd.Swim();
        }
        public void ShouldGetRubberDuckCanSwimButNotFlyAndSqueakQuack()
        {
            var quack = new RubberDuck();

            quack.SetFlyBehaviour(new FlyNoWay());

            quack.SetQuackBehaviour(new Squeak());

            quack.Display();

            quack.PerformQuack();

            quack.Swim();

            quack.Display();
        }
Example #8
0
        static void Main(string[] args)
        {
            Bird christianBird = new RubberDuck();

            christianBird.Display();
            christianBird.SetFlyBehavior(new YesFly());
            christianBird.PerformFly();
            christianBird.PerformQuack();
            christianBird.Swim();

            Bird mortyBird = new Swallow();

            mortyBird.Display();
            mortyBird.PerformFly();
            mortyBird.PerformQuack();
            mortyBird.Swim();
        }
Example #9
0
        static void Main(string[] args)
        {
            Duck exp1 = new Duck();

            Console.WriteLine("Я живая утка:\n");
            exp1.Fly();
            exp1.Swim();
            exp1.Quack();
            WoodenDuck exp2 = new WoodenDuck();

            Console.WriteLine("\nЯ деревянная утка:\n");
            exp2.Fly();
            exp2.Swim();
            exp2.Quack();
            RubberDuck exp3 = new RubberDuck();

            Console.WriteLine("\nЯ резиновая утка:\n");
            exp3.Fly();
            exp3.Swim();
            exp3.Quack();
            Console.ReadLine();
        }
Example #10
0
        static void Main(string[] args)
        {
            var mallardDuck = new MallardDuck();

            mallardDuck.QuackBehavior = new QuackAsNormal();
            mallardDuck.FlyBehavior   = new FlyWithWings();
            Console.WriteLine($"Mallard duck {new string('-', 50)}");
            mallardDuck.Swim();
            mallardDuck.PerformQuack();
            mallardDuck.PerformFly();

            var redheadDuck = new RedheadDuck();

            redheadDuck.QuackBehavior = new QuackAsNormal();
            redheadDuck.FlyBehavior   = new FlyWithWings();
            Console.WriteLine($"Redhead duck {new string('-', 50)}");
            redheadDuck.Swim();
            redheadDuck.PerformQuack();
            redheadDuck.PerformFly();

            var rubberDuck = new RubberDuck();

            rubberDuck.QuackBehavior = new Sqeak();
            rubberDuck.FlyBehavior   = new FlyNoWay();
            Console.WriteLine($"Rubber duck {new string('-', 50)}");
            rubberDuck.Swim();
            rubberDuck.PerformQuack();
            rubberDuck.PerformFly();

            var decoyDuck = new DecoyDuck();

            decoyDuck.QuackBehavior = new Mute();
            decoyDuck.FlyBehavior   = new FlyNoWay();
            Console.WriteLine($"Decoy duck {new string('-', 50)}");
            decoyDuck.Swim();
            decoyDuck.PerformQuack();
            decoyDuck.PerformFly();
        }