Beispiel #1
0
        static void Main(string[] args)
        {
            Duck duck = new MallardDuck();

            PrintMsg(duck);
            sb.AppendLine();


            duck = new RedHeadDuck();
            duck.SetFlyBehavior(Delegation.New <FlyBehavior>(typeof(NoVoice)));
            duck.SetQuackBehavior(new QuackBehavior(typeof(Squeak)));
            PrintMsg(duck);
            sb.AppendLine();

            duck = new RedHeadDuck();
            duck.SetQuackBehavior(new QuackBehavior(typeof(NoVoice)));
            PrintMsg(duck);
            sb.AppendLine();

            duck = new RubberDuck();
            duck.SetFlyBehavior(Delegation.New <FlyBehavior>(typeof(FlyNoWay)));           //new FlyBehavior(typeof(FlyNoWay))
            duck.SetQuackBehavior(new QuackBehavior(typeof(MuteQuack)));
            PrintMsg(duck);
            sb.Append(duck.Swim());
            sb.AppendLine();

            Console.WriteLine(sb.ToString());
            Console.ReadLine();
        }