Applicability

    Use the Strategy pattern when

Structure

Participants

    Strategy
        declares an interface common to all supported algorithm

    ConcreteStrategy
        implements the algorithm using the Strategy interface

    Context
        is configured with an instance of a ConcreteStrategy.
        may define an interface that lets Strategy access its data.

Collaborations

    Strategy and Context interact to implement the chosen algorithm.
    Three possibilities
    1) Context passes required data to Strategy as part of method arguments
    2) Context passes a reference to itself to Strategy and defines an interface for
        accessing the data
    3) Strategy maintains a reference to Context.

    A context forwards requests from its clients to its strategy.  Clients usually create and pass a
    ConcreteStrategy object to the context. They interact with the context thereafter.

BACK    NEXT