Search code examples
design-patternsstrategy-pattern

strategy pattern and number of methods in the strategy Interface


When Strategy patten is chosen as a solution, is number of method in the strategy interface should be always one ? i.e execute()

Is strategy pattern chosen wrongly if I need to have more than one method in the interface ?

thanks in advance


Solution

  • No you can have more than one method on your strategy interface. However, in order for your strategy object to actually use the Strategy pattern, at least one of the method implementations should differ between the different strategies.