static void Main(string[] args)
        {
            IFlyBehaviour flyNoWay     = new FlyNoWay();
            IFlyBehaviour flyWithWings = new FlyWithWings();
            Duck          mallardDuck  = new MallardDuck();

            mallardDuck.SetFlyBehaviour(flyWithWings);

            Duck redheadDuck = new RedheadDuck();

            redheadDuck.SetFlyBehaviour(flyWithWings);

            Duck rubberDuck = new RubberDuck();

            rubberDuck.SetFlyBehaviour(flyNoWay);

            Duck decoyDuck = new DecoyDuck();

            decoyDuck.SetFlyBehaviour(flyNoWay);


            List <Duck> listDucks = new List <Duck>
            {
                mallardDuck,
                redheadDuck,
                rubberDuck,
                decoyDuck
            };


            foreach (var duck in listDucks)
            {
                duck.Fly();
            }
        }
        public static void Main(string[] args)
        {
            Duck mallardDuck = new MallardDuck();

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

            mallardDuck.SetFlyBehaviour(new RocketFly());
            mallardDuck.PerformFly();
        }
Exemple #3
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Duck mallard = new MallardDuck();

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

            mallard.SetFlyBehaviour(new FlyNoWay());
            mallard.PerformFly();
        }