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(); }
static void Main(string[] args) { Bird christianBird = new RubberDuck(); christianBird.Display(); christianBird.SetFlyBehavior(new YesFly()); christianBird.PerformFly(); christianBird.PerformQuack(); christianBird.Swim(); Bird mortyBird = new Swallow(); mortyBird.Display(); mortyBird.PerformFly(); mortyBird.PerformQuack(); mortyBird.Swim(); }