Strategy Pattern vs Template Method Pattern

  • Template Method Pattern is based on inheritance: it lets you alter parts of an algorithm by extending those parts in subclasses
  • Strategy Pattern is based on composition: you can alter parts of the object’s behavior by supplying it with different strategies that correspond to that behavior
  • Template Method Pattern works at the class level, so it’s static after compile-time
  • Strategy Pattern works on the object level, letting you switch behaviors at runtime