Strategy Pattern

What is Strategy Pattern?

Strategy pattern is a commonly used behavioural pattern1. Strategy Pattern is mostly a way to change the behaviour of an algorithm at runtime.

The strategy pattern:

  • defines a family of algorithms,
  • encapsulates each algorithm, and
  • makes the algorithms interchangeable within that family.

Consequences

Think twice before implementing this pattern. You have to be sure your need is to change an algorithm frequently. You have to clearly anticipate the future, otherwise, this pattern will be more expensive than a basic implementation.

Continue reading