The Strategy Design Pattern

Introduction

The Abstraction Principle states:

The interface of a class should be independent of its implementation

(The interface of a class is simply all of its public operations. Recall that an operation is a method minus its implementation.)

This is often taken to imply that the implementation of a method— the algorithm used—is none of the client's business. The Strategy Pattern turns the Abstraction Principle upside down by allowing the client to not only discover the algorithm used by a method, but to also change the algorithm dynamically. To achieve this we encapsulate the possible algorithms used by a method as separate, but interchangeable objects.

Examples

Sorting Lists

E-Commerce

Human Resources

Investment Strategies

Layout Managers in Java

Strategies as Agent Behaviors