抽象クラス:
abstract class PersistentList<T>
public static PersistentList<T> GetInstanceOfDerivedClass()
{
//???
}
派生クラス:
public class Managers : PersistentList<Manager>
だから、私はしたいです:
Managers managers = Managers.GetInstanceOfDerivedClass();
それは可能ですか?
選択肢は次のとおりです。
int clientID = 3;
Managers managers = Managers.For("Client", new { ClientID = clientID});
Managers managers = new Managers(new { ClientID = clientID });
Managers managers = new Managers();
managers.ClientID = clientID;
managers.Load("ForClient");
//alternatively:
Database.Load(managers, "ForClient");
//this works, however requires the above code in the constructor.
Managers managers = new Managers(clientID);
//If the static method on the abstract class (Managers.For) could determine
//the type calling, it would eliminate the need for repetitive constructors.
上記のすべてが利用可能で、良いテクニックを決定しようとしているだけです。