コード例 #1
0
ファイル: Program.cs プロジェクト: Godfather27/designPatterns
        static void Main(string[] args)
        {
            // Create Instances of Strategies and Contexts.
            Squeak theSqueak = new Squeak ();
            Quack theQuack = new Quack ();
            MuteQuack theMuteQuack = new MuteQuack ();
            FlyWithWings theFly = new FlyWithWings ();
            Flyless theFlyless = new Flyless ();

            Duck magicDuck = new MallardDuck(theQuack, theFly);
            Duck rorschachDuck = new RedheadDuck (theMuteQuack, theFlyless);

            // Call functions.
            magicDuck.display();
            magicDuck.performQuack();
            magicDuck.performFly();
            Console.Out.WriteLine ();

            rorschachDuck.display();
            rorschachDuck.performQuack();
            rorschachDuck.performFly();
            Console.Out.WriteLine ();

            // Assign new Strategies to Instances.
            magicDuck.QuackBehaviour = theSqueak;
            magicDuck.FlyBehaviour = theFlyless;
            rorschachDuck.QuackBehaviour = theQuack;
            rorschachDuck.FlyBehaviour = theFly;

            // Call functions.
            magicDuck.display();
            magicDuck.performQuack();
            magicDuck.performFly();
            Console.Out.WriteLine ();

            rorschachDuck.display();
            rorschachDuck.performQuack();
            rorschachDuck.performFly();

            Console.In.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Godfather27/designPatterns
        static void Main(string[] args)
        {
            // Create Instances of Strategies and Contexts.
            Squeak       theSqueak    = new Squeak();
            Quack        theQuack     = new Quack();
            MuteQuack    theMuteQuack = new MuteQuack();
            FlyWithWings theFly       = new FlyWithWings();
            Flyless      theFlyless   = new Flyless();

            Duck magicDuck     = new MallardDuck(theQuack, theFly);
            Duck rorschachDuck = new RedheadDuck(theMuteQuack, theFlyless);

            // Call functions.
            magicDuck.display();
            magicDuck.performQuack();
            magicDuck.performFly();
            Console.Out.WriteLine();

            rorschachDuck.display();
            rorschachDuck.performQuack();
            rorschachDuck.performFly();
            Console.Out.WriteLine();

            // Assign new Strategies to Instances.
            magicDuck.QuackBehaviour     = theSqueak;
            magicDuck.FlyBehaviour       = theFlyless;
            rorschachDuck.QuackBehaviour = theQuack;
            rorschachDuck.FlyBehaviour   = theFly;

            // Call functions.
            magicDuck.display();
            magicDuck.performQuack();
            magicDuck.performFly();
            Console.Out.WriteLine();

            rorschachDuck.display();
            rorschachDuck.performQuack();
            rorschachDuck.performFly();

            Console.In.ReadLine();
        }