Thomas Andrews
Jul 10, 2017 · 1 min read

From a pedagogical point of view, I dislike this example, because it might cause confusion between mere polymorphism and the specific case of the strategy pattern. In particular, the name “Car” doesn’t indicate that it is representing a strategy, but rather an entity object of some sort, and vehicles have a lot of methods other than “accelerated_to.”

A strategy pattern implementation should either end in the word “Strategy” or “Policy” or “er” or “or” suffix — a noun which indicates what the object does. “SalesTaxCalculator,” “DeckShuffler,” “DataStorageStrategy”, “VacationTimePolicy.”

A driver doesn’t use a “car strategy,” a driver uses a car. While abstractly, the above code meets the strategy pattern requirements, I think it might lead to a misunderstanding of what the pattern is trying to do.

    Thomas Andrews

    Written by