からラップされたオブジェクトでのアクセス値は、私はデコレータパターン - デコレータ
が、私はこのコードを持っていると言うことができますDecoratorパターンについて質問があり
interface IThingy
{
void Execute();
}
internal class Thing : IThingy
{
public readonly string CanSeeThisValue;
public Thing(string canSeeThisValue)
{
CanSeeThisValue = canSeeThisValue;
}
public void Execute()
{
throw new System.NotImplementedException();
}
}
class Aaa : IThingy
{
private readonly IThingy thingy;
public Aaa(IThingy thingy)
{
this.thingy = thingy;
}
public void Execute()
{
throw new System.NotImplementedException();
}
}
class Bbb : IThingy {
private readonly IThingy thingy;
public Bbb(IThingy thingy)
{
this.thingy = thingy;
}
public void Execute()
{
throw new System.NotImplementedException();
}
}
class Runit {
void Main()
{
Aaa a = new Aaa(new Bbb(new Thing("Can this be accessed in decorators?")));
}
}
我々は2つのデコレータによってラップされたクラスと呼ばれるものを持っていますAAAとBBB
どのように私は基本CLを作ってみました、AAAまたはBBB
からのI最適なアクセス文字列値(シングである)「CanSeeThisValue」缶それらのすべてのためのお尻、しかし、彼らは同じベースを共有している間、彼らはベースの同じインスタンスを共有しません
代わりに各コンストラクタに値を渡す必要がありますか?
デコレータは、彼らがラップされているものは何でものパブリック・インタフェースを使用して機能を強化、彼らは通常、その先何の知識を持っている必要があります。 –
そのフィールドをベースクラスで静的にすることはできますか?または、IThingyに新しいプロパティを追加しますか?こうすることで、装飾されたクラスをループ内で使用して、そのプロパティの値を取得することができます。 –