membersound
membersound

Reputation: 86687

Why does strategy pattern use implements instead extends?

Why does the strategy pattern make use of implements instead of extends? Because I would assume that StrategyA is-a StrategyBase, which would rather lead me to extending the base strategy than implementing it as an interface.

So, would it be wrong to apply the strategy pattern with "extends"? And what are advantages if I'm using it with interface?

Upvotes: 0

Views: 148

Answers (2)

Marko Topolnik
Marko Topolnik

Reputation: 200148

If you have no common code to put into your strategy base type, you are achieving nothing by using an abstract class instead of an interface, except for constraining the clients of such API to using a dedicated class for the strategy, where they would perhaps want a single class implement several interfaces.

Upvotes: 2

rbhawsar
rbhawsar

Reputation: 813

as per my info : using extends , you will not be able to extend any other class. and if not definition is required for methods why not to used interface.

Upvotes: 1

Related Questions