次のようなクラスを持つC#コンポーネントがあります。
namespace SharedComponent{
class TestResult {
//several members
}
}
別の既存のC#アプリケーションでは、このコンポーネントを参照しています。この同じクラスをインスタンス化する必要がありますが、以下のように追加の識別子を使用します。
namespace ClientApplication {
class TestResult
{
//exact same members as above including methods
//actually the shared component class was created by gleaming
//that from this application!
int PersonID; //additional identifier
//not suitable to have in the shared component
}
}
クライアントアプリケーションには、追加の識別子に依存するいくつかのメソッドがあります。そのため、コピーコンストラクターをエミュレートしてこのオブジェクトを作成し、追加のパラメーターを入力するのは非常に魅力的です。このようにして、クラスへの変更を最小限に抑えながら、既存の関数をそのまま使用できます。
別の方法は、クライアント側の実装への参照として残りの詳細を追加することです。
namespace ClientApplication {
class TestResult {
SharedComponent.TestResult trshared = new SharedComponent.TestResult()
//but this warrants I have my class methods to delegate
//to the sharedcomponent throughout ; example below
internal bool IsFollowUp(ClientApplication.TestResult prevTest)
{
//a similar method is being used
//where a function takes the class object as parameter
trshared.IsFollowUp(prevTest.trshared);
}
int PersonID; //additional identifier
}
}
どちらのオプションが良いですか?この点でのベストプラクティスは何ですか?
環境:VS2008、C#、WinXP / Win7