Exemplo n.º 1
0
        public IBehavior CreateBehavior(Duck duckType)
        {
            if (duckType.GetType() == typeof (Mallard)) {
                return new MallardBehavior();
            }

            if (duckType.GetType() == typeof (SicklyDuck)) {
                return new SicklyDuckBehavior(duckType);
            }

            if (duckType.GetType() == typeof (RubberDuck)) {
                return new RubberDuckBehavior(duckType);
            }

            if (duckType.GetType() == typeof (CrazyDuck)) {
                return new CrazyDuckBehavior();
            }

            if (duckType.GetType() == typeof (GrapeDuck))
            {
                return new GrapeDuckBehavior(duckType);
            }

            throw new Exception("Duck Type is not valid.");
        }
Exemplo n.º 2
0
 public RubberDuckBehavior(Duck duck)
 {
     Duck = duck;
 }
Exemplo n.º 3
0
 public GrapeDuckBehavior(Duck duck)
 {
     _duck = duck;
 }
Exemplo n.º 4
0
 public SicklyDuckBehavior(Duck duck)
 {
     Duck = duck;
 }