// Use this for initialization
    void Start()
    {
        Duck millard = new MallardDuck();

        millard.PerformQuack();
        millard.PerformFly();

        millard.SetFlyBehavior(new FlyNoWay());
        millard.SetQuackBehavior(new MuteQuack());

        millard.PerformQuack();
        millard.PerformFly();
    }
        public void Duck_Behaviors_CanChangeBehaviorAtRuntime()
        {
            Duck mallard = new MallardDuck();

            mallard.Display();

            Assert.AreEqual("Quack!", mallard.Quack());
            Assert.AreEqual("I can fly!", mallard.Fly());

            mallard.SetQuackBehavior(new MuteQuack());
            mallard.SetFlyBehavior(new FlyNoWay());

            Assert.AreEqual("<silence>", mallard.Quack());
            Assert.AreEqual("I can't fly", mallard.Fly());
        }
Example #3
0
        static void Main(string[] args)
        {
            MallardDuck mallard = new MallardDuck();

            mallard.Quack();
            mallard.SetQuackBehavior(new Squeak());
            Console.WriteLine("-- Change Quack Behavior --");
            mallard.Quack();

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

            var model = new ModelDuck("Model Duck");

            model.Fly();
            model.SetFlyBehavior(new FlyRocketPowered());
            Console.WriteLine("-- Change Quack Behavior --");
            model.Fly();
        }
Example #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Create Mallard Duck");
            Console.WriteLine();

            Duck duck = new MallardDuck();

            duck.Display();
            duck.PerformQuack();
            duck.PerformFly();
            duck.Swim();
            Console.WriteLine();

            Console.WriteLine("Change the state");
            Console.WriteLine();
            duck.SetFlyBehavior(new FlyRocketPowered());
            duck.SetQuackBehavior(new MuteQuack());
            duck.Display();
            duck.PerformQuack();
            duck.PerformFly();
            duck.Swim();
        }