Implements the algorithm using the Strategy interface
Context (e.g., Composition)
Configured with a ConcreteStrategy object
Maintains a reference to a Strategy object
May define an interface that lets Strategy access its data
Strategy: Collaborations
Strategy and Context interact to implement the chosen algorithm:
A Context passes data required by the algorithm to the Strategy in the call
A Context can pass itself as an argument to Strategy operations
A Context forwards requests from its clients to its Strategy
Clients usually create and pass a ConcreteStrategy to the context
Typically, the client chooses from a family of ConcreteStrategy classes
Strategy: Advantages
Families of related algorithms
An alternative to subclassing the Context class
Eliminate conditional statements
Wide choice of implementation
Strategy: Disadvantages
Clients must pick which algorithm to use
Communication overhead between Strategy and Context
Increases the number of objects
Implementation
Known Uses
RTL System for compiler code optimization [JML92]- strategies define different register allocation schemes (RegisterAllocator), and instruction set scheduling policies (RISCscheduler, CISCscheduler)
ET++SwapsManager calculation engine framework computes prices for different financial instruments [EG92]
ConcreteStrategy classes for generating cash flows, valuing swaps, and calculating discount factors