SE450: Strategy Pattern [38/72] Previous pageContentsNext page

Context

  1. A class can benefit from different variants for an algorithm
  2. Clients sometimes want to replace standard algorithms with custom versions

Solution

  1. Define an interface type that is an abstraction for the algorithm
  2. Actual strategy classes realize this interface type.
  3. Clients can supply strategy objects
  4. Whenever the algorithm needs to be executed, the context class calls the appropriate methods of the strategy object

Previous pageContentsNext page