デリゲートの形式でオーバーライド可能なメソッドを持つクラスを作成したいと思います。
基本的にはインターフェイスを作成したいのですが、少し違うものにしたいたびに新しいクラスを作成する必要はありません。
さらに、デリゲートを構造体の他の多くの変数にバンドルしたいと思います。
次に、いくつかの詳細を示します。
class Gun
{
public delegate void ShootDelegate;
// There are more variables, I'm just using this one as an example
public double fireRate;
public Gun(GunStats stats)
{
this.Shoot = stats.Shoot;
this.fireRate = stats.fireRate;
}
public ShootDelegate Shoot;
}
struct GunStats
{
public ShootDelegate Shoot;
public double fireRate;
}
だったらこんな銃を作ってみたい
GunStats stats;
stats.fireRate = 3;
stats.Shoot = new delegate() { this.fireRate++; /* stupid example */ };
new Gun(stats);
ただし、デリゲートを作成すると、明らかに内部クラス変数と対話できません。
これを処理する最良の方法は何ですか?