Brendan Ang

Search

Search IconIcon to open search

Strategy Pattern

Last updated Nov 8, 2022 Edit Source

# Strategy Pattern

# Problems we want to solve

  1. A set of interchangeable algorithms or objects that can be decided at run-time
  2. Extensible set of strategies: Open-Closed Principle

Context refers or uses the Strategy interface for performing the algorithm. A and B classes implement the Strategy interface which gives the concrete algorithms.

# Pros

  1. Encapsulation
  2. Hides implementation
  3. Allows behaviour change at runtime

# Cons

  1. Complexity if overused