zondag 7 maart 2010

Strategy pattern

  • Ducks fly and quack
  • Rubber ducks don't fly and quack
  • => Different fly and quack behaviour
Encapsulate what varies! => Fly and quackbehaviour.

How
  • Create duckbehaviour- and flybehaviour-interfaces (Program to interface)
  • Different implementation in the concrete behaviour classes.
  • Duck base-class with reference to FlyBehaviour- and QuackBehaviour-interface.
  • The concrete Duck-classes will then use the appropriate implementation of the behaviours. (Composition)

Geen opmerkingen: