Пример #1
0
        static void Main(string[] args)
        {
            Duck d = new MallardDuck();

            d.quackingBehaviour = new Quack();
            d.flyingBehaviour   = new FlyWithWings();
            d.PerformQuack();
            Duck d2 = new ModelDuck();

            d2.PerformFly();
            d2.flyingBehaviour = new FlyWithRockets();
            d2.PerformFly();
            Console.ReadLine();
        }
Пример #2
0
        private static void Main(string[] args)
        {
            //The startegy pattern: defines a family of algorithms, encapsulates each one, and makes them interchangeable.
            //Strategy lets the algorithm vary independently from clients that use it.
            Duck mallard = new MallardDuck();

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

            Duck modelDuck = new ModelDuck();

            modelDuck.PerformQuack();
            modelDuck.PerformFly();

            modelDuck.SetFlyBehavior(new FlyRocketPowered());
            modelDuck.PerformFly();
            Console.ReadLine();
        }