Saturday, January 28, 2012

The startegy pattern

Definition: The Strategy pattern defines a family of algorithms whose individual behaviors are encapsulated allowing them to be interchangeable. Strategy lets the algorithm vary independently from clients that use it.




The above example illustrates the strategy pattern. The client in this case Jetplane is a subclass of type Plane. The Jetplane uses the flight algorithms Jetflight. Each flight algorithm is encapsulated in its own concrete class. The jet plane could very easily use a different flight algorithm making them  interchangeable.

No comments: