Abstract class:
abstract class PersistentList<T>
public static PersistentList<T> GetInstanceOfDerivedClass()
{
//???
}
Derived class:
public class Managers : PersistentList<Manager>
So, I’d like to:
Managers managers = Managers.GetInstanceOfDerivedClass();
Is that possible?
Choices are:
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.
All the above are available, just trying to decide on a good technique.
I think this is about the simplest it’ll be if you need strong typing (i.e. that the method will return
Managers, not justPersistentList<Manager>when requesting aManagers):You might also do:
This lets you use the signature in your example,
Managers.GetInstanceOfDerivedClass(). I find this design pattern confusing, however, and would discourage its use.