C#でテンプレート/抽象クラスのコンストラクターの戦略を実装する最良の方法は何ですか? コンストラクター内の文字列の解析に基づいたクラスがいくつかあります。解析は、キーと値のペアのリストを作成する静的メソッドで行われ、すべてのクラスに共通ですが、一部のフィールドはすべてのクラスに共通であるため、抽象テンプレート クラスを使用します。
問題は、抽象基本クラスのコンストラクターの実装を継承する方法が見つからないことです。それ以外の場合は、基本クラスにコンストラクター戦略を実装し、一部の抽象メソッド内でリストの処理を強制します。
編集:テンプレートクラスの動作しないコードを追加
public abstract class XXXMessageTemplate
{
public XXXMessageTemplate(string x) // implementation for the constructor
{
Parse(x);//general parse function
CommonFields();//filling common properties
HandlePrivateProperties();//fill individual properties
HandlePrivateStructures();//fill individual structures
}
abstract void HandlePrivateProperties();
abstract void HandlePrivateStructures();
}
The actual messages should not implement any constructor and only implement the HandlePrivateProperties and HandlePrivateStructures functions.