Strategy

Problem

An object needs to dynamically change the algorithm used by one of its methods. For example, an object representing a list of strings may want to allow users to change the algorithm used by it's sort method. Although the fields of an object can be changed dynamically, the implementations of its methods are fixed by the compiler.

Solution

Represent a method's algorithm as an object that can be dynamically switched:

Java Implementation

Warrior.java