Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Strategy Pattern");

            var rubberDuck   = new Duck(new CannotFly(), new CannotQuack(), new CannotSwim());
            var muteDuck     = new Duck(new CanFly(), new CannotQuack(), new CanSwim());
            var disabledDuck = new Duck(new CannotFly(), new CanQuack(), new CannotSwim());

            System.Console.WriteLine("Rubber duck behaviour.");
            rubberDuck.Fly();
            rubberDuck.Swim();
            rubberDuck.Quack();

            System.Console.WriteLine("Mute duck behaviour.");
            muteDuck.Fly();
            muteDuck.Swim();
            muteDuck.Quack();

            System.Console.WriteLine("Disabled duck behaviour.");
            disabledDuck.Fly();
            disabledDuck.Swim();
            disabledDuck.Quack();

            Console.ReadLine();
        }
Пример #2
0
        static void Main(string[] args)
        {
            Duck cityDuck = new Duck(null, new SwimUnderWater(), new FlyVeryHigh());

            cityDuck.Fly();
            cityDuck.Swim();
            Console.ReadLine();
        }
Пример #3
0
        static void Main(string[] args)
        {
            Duck savageDuck = new Duck(new SupersonicFly(), new LongQuack());

            savageDuck.Fly();
            savageDuck.Quack();

            Console.WriteLine("--------------------------------------------");

            Duck domesticDuck = new Duck(new LowRangeFly(), new ShortQuack());

            domesticDuck.Fly();
            domesticDuck.Quack();
        }
Пример #4
0
        static void Main(string[] args)
        {
            var jetPoweredRobotDuck = new Duck(new JetFlyBehavior(), new RobotQuackBehavior());

            Console.WriteLine("jetPoweredRobotDuck  -- ");
            jetPoweredRobotDuck.Fly();
            jetPoweredRobotDuck.Quack();
            Console.WriteLine();

            Console.WriteLine("normalDuck-- ");
            var normalDuck = new Duck(new SimpleFlyBehavior(), new NormalQuackBehavior());

            normalDuck.Fly();
            normalDuck.Quack();
            Console.Read();
        }
Пример #5
0
        static void Main(string[] args)
        {
            Duck cityDuck    = new Duck(new NoFlying(), new ShortSwiming(), new ShortWalking());
            Duck countryDuck = new Duck(new HighFlying(), new NoSwiming(), new RunWalking());
            Duck rubberDuck  = new Duck(new NoFlying(), new PhelpsSwiming(), new NoWalking());

            Console.WriteLine("City Duck say something!");
            cityDuck.Fly();
            cityDuck.Walk();
            cityDuck.Swim();
            Console.WriteLine("Country Duck SPEAK!");
            countryDuck.Fly();
            countryDuck.Walk();
            countryDuck.Swim();
            Console.WriteLine("Rubber Duck? Ruuuuubbbber Duuuuck?");
            rubberDuck.Fly();
            rubberDuck.Walk();
            rubberDuck.Swim();
        }