All challenges
Multiple ChoiceBeginner 45s

Template method vs strategy

You want to share a fixed multi-step algorithm but allow subclasses to vary *only one* step. The steps are unlikely to be needed independently. Which is the better fit?
Options
  1. 1Strategy: inject a whole encapsulated algorithm object through the constructor so it varies at runtime
  2. 2Observer: register listener objects that are notified as each step of the algorithm runs internally
  3. 3Command: encapsulate each individual step of the algorithm as its own request object with an execute method
  4. 4Template Method: the base class owns the algorithm skeleton and subclasses override hook steps

Think you can answer under pressure?

Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.

Play this in a 3-minute battle