Here\'s what I have so far:
namespace Strategy
{
interface IWeaponBehavior
{
void UseWeapon();
}
}
namespace Strategy
{
class Knife
If your characters all have their own specific weapon, you don't actually need to use the strategy pattern. You could use plain polymorphism. But the strategy pattern could be cleaner anyway.
You just need to intitialize the weapon:
public class Character
{
IWeapenBehavior weapon;
public Attack()
{
weapon.UseWeapon();
}
}
public class Thief : Character
{
Thief()
{
weapon = new Knife();
}
}
In the code that controls your Characters, you can call the Attack()
method.