Strategy Pattern – Using Abstract Class Instead of Interface

abstract classdesign-patternsinterfacesstrategy

Is the strategy in the strategy pattern always an interface? What pattern would it be when the strategy is abstract?

Best Answer

Is the strategy in the strategy pattern always an interface?

That depends on what you mean by "interface". If you mean the standard general programming meaning of "an abstraction that hides its details" that is used in such words as "User Interface (UI)", "Application Programming Interface (API)", "Application Binary Interface (ABI)", "Network Interface", "Audio Interface" and so on, then yes, it is always an interface. That is, after all, the whole point of the Strategy Pattern.

If you mean the specific Java / C♯ interface keyword, then no, obviously not, since it doesn't even exist in the overwhelming majority of languages.

What pattern would it be when the strategy is abstract?

Strategy.

There is no mention of interface on the Strategy Pattern page of the Portland Pattern Repository on Ward's Wiki, nor is there any mention of it in the "Gang of Four Book" (Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, John Vlissides, Ralph Johnson, and Richard Helm).