これが私がこれまでに持っているものです:
namespace Strategy
{
interface IWeaponBehavior
{
void UseWeapon();
}
}
namespace Strategy
{
class Knife : IWeaponBehavior
{
public void UseWeapon()
{
Console.WriteLine("You used the knife to slash the enemy! SLASH SLASH!");
}
}
}
namespace Strategy
{
class Pan : IWeaponBehavior
{
public void UseWeapon()
{
Console.WriteLine("You use the pan! 100% Adamantium power! BONG!");
}
}
}
Character.cs スーパークラスがあるとします。子クラスがより具体的になるように、そのスーパークラスが武器の動作をどのように実装できますか。
namespace Strategy
{
class Character
{
public IWeaponBehavior weapon;
public Character(IWeaponBehavior specificWeapon)
{
weapon = specificWeapon;
}
}
}
namespace Strategy
{
class Thief : Character
{
}
}
どうすればこれを実装できますか? 実際のコードがどうあるべきかについて非常に混乱しています。
質問が多すぎるかもしれませんが、実際のコードを書いて研究できるようにしていただけると助かります。コードを見て学ぶ。:P 多くの人がこの質問から恩恵を受けることができます.