Using an abstract class or interface as strategy?
I watched this video explaining the Strategy Pattern: http://www.youtube.com/watch?v=94t2ayF1l3o
It gives an example for a game where the context is the character, the strategy a weapon. The concrete strategies can be things like an axe, sword, etc.
It used an interface for weapon. I was thinking about this and I thought an abstract class could be better here in this case. Since you do not want to be able to create a new object of this, which could be possible with an interface doing:
new IWeapon() {//implementation here
};
What would be pros and cons using the weapon as an interface vs using it as an abstract class? Or is example giving in this video just a bad example in how to use the strategy pattern?
( I'm not looking for an answer saying use what you feel comfortable with ;) )
I watched this video explaining the Strategy Pattern: http://www.youtube.com/watch?v=94t2ayF1l3o
It gives an example for a game where the context is the character, the strategy a weapon. The concrete strategies can be things like an axe, sword, etc.
It used an interface for weapon. I was thinking about this and I thought an abstract class could be better here in this case. Since you do not want to be able to create a new object of this, which could be possible with an interface doing:
new IWeapon() {//implementation here
};
What would be pros and cons using the weapon as an interface vs using it as an abstract class? Or is example giving in this video just a bad example in how to use the strategy pattern?
( I'm not looking for an answer saying use what you feel comfortable with ;) )
No comments:
Post a Comment