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.

Also Known as
    Policy

Motivation
    You have a situation whereby you manipulate a set of objects in different ways
    depending on the algorithm.

    For instance, a word processor may have several line breaking strategies.
    It manipulates lines, paragraphs and characters.

    You don't want a case statement in the client that explicity specifies each strategy.
    This makes it difficult to vary existing algorithms and add new ones.

Solution? Encapsulate the algorithm that changes.

Please note all material is taken from the book Design Patterns: Elements of Resusable Object-Oriented Software.
See source listed at the end.

BACK    NEXT