예제 #1
0
        private void CreateMallardDuckWithRocketAndSqueak()
        {
            Duck mallardDuck = new MallardDuck();

            mallardDuck.SetFlyBehavior(new FlyRocketPowered());
            mallardDuck.SetQuackBehavior(new Squeak());
            mallardDuck.Display();
            mallardDuck.PerformFly();
            mallardDuck.PerformQuack();
        }
예제 #2
0
        static void Main(string[] args)
        {
            Duck myDuck = new MallardDuck();

            myDuck.Display();
            myDuck.PerformFly();
            myDuck.PerformQuack();
            myDuck.SetFlyBehavior(new FlyWithWingsTypeTwo());
            myDuck.SetQuackBehavior(new NoQuack());
            myDuck.PerformFly();
            myDuck.PerformQuack();

            myDuck = new RubberDuck();
            myDuck.Display();
            myDuck.PerformFly();
            myDuck.PerformQuack();
            myDuck.SetFlyBehavior(new FlyWithJet());
            myDuck.SetQuackBehavior(new QuackLikeMallardDuck());
            myDuck.PerformFly();
            myDuck.PerformQuack();
        }