Strategy

Intent

Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

-Design Patterns, GoF

 

Also Known As

Policy

 

Object Oriented Principles

The Strategy design pattern embodies two fundamental tenets of object-oriented (OO) design: encapsulate the concept that varies and program to an interface, not an implementation. - JavaWorld

 

Questions

1) How do you pass in the data (or context) that a Strategy needs to do its job? Do you pass in the same data, regardless of the specific concrete Strategy? What happens if some data that a Strategy needs is not in the context?

2) What are the advantages of tightly coupling the Strategy with its Context?

3) How does the Strategy pattern differ from standard inheritance?

4) How are Strategy objects created for a specific client?

5) How are the Adapter pattern and Strategy pattern similar? How are they different?

 

Examples Which are Strategies?

1) CalendarSet, USCalendarSet, CanadaCalendarSet Patterns in Java, Mark Grand

2) Swing Borders JavaWorld Example

 

References

         The Strategy Design Pattern, Antonio Garcia (Rice University)

         Strategy for Success, David Geary (JavaWorld.com, April 2002)

         Strategy (Data & Object Factory)