예제 #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.");
        }
예제 #2
0
 public RubberDuckBehavior(Duck duck)
 {
     Duck = duck;
 }
예제 #3
0
 public GrapeDuckBehavior(Duck duck)
 {
     _duck = duck;
 }
예제 #4
0
 public SicklyDuckBehavior(Duck duck)
 {
     Duck = duck;
 }