background preloader

Strategy

Facebook Twitter

Strategy Design Pattern. Intent Define a family of algorithms, encapsulate each one, and make them interchangeable.

Strategy Design Pattern

Strategy lets the algorithm vary independently from the clients that use it.Capture the abstraction in an interface, bury implementation details in derived classes. Problem. Strategy Pattern. Motivation There are common situations when classes differ only in their behavior.

Strategy Pattern

For this cases is a good idea to isolate the algorithms in separate classes in order to have the ability to select different algorithms at runtime. Intent. Strategy pattern. Defines a family of algorithms,encapsulates each algorithm, andmakes the algorithms interchangeable within that family.

Strategy pattern

Strategy lets the algorithm vary independently from clients that use it.[1] Strategy is one of the patterns included in the influential book Design Patterns by Gamma et al. that popularized the concept of using patterns to describe software design. For instance, a class that performs validation on incoming data may use a strategy pattern to select a validation algorithm based on the type of data, the source of the data, user choice, or other discriminating factors. These factors are not known for each case until run-time, and may require radically different validation to be performed. The validation strategies, encapsulated separately from the validating object, may be used by other validating objects in different areas of the system (or even different systems) without code duplication.