私は以下のようにクラスを持つC#のコンポーネントがあります。私はこのコンポーネントを参照していると私は、この同じクラスをインスタンス化する必要がある別の既存のC#アプリケーションでクラス間委任 - ベストプラクティス
namespace SharedComponent{
class TestResult {
//several members
}
}
をが、追加の識別子を持ちます以下のように。
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
}
}
クライアントアプリケーションには、追加の識別子に依存するいくつかの方法があります。ですからコピーコンストラクタをエミュレートしてこのオブジェクトを作成し、追加パラメータを入力することは私にとって非常に魅力的です。このようにして、既存の関数をそのまま使用することができます。
もう1つの方法は、残りの詳細をクライアント側の実装への参照として追加することです。
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の
クライアントアプリケーションクラスはオリジナルから継承できますか? – sq33G