[英]Create instance of the class from base class
I have DataAccess class which is derived from DataAccessor. 我有从DataAccessor派生的DataAccess类。 DataAccessor class is the DB base class which I use in all all projects. DataAccessor类是我在所有所有项目中使用的DB基类。
Instance method is the helper to create new instance of the DataAccess class. 实例方法是创建DataAccess类的新实例的助手。 I would like to move Instance method to DataAccessor base class and create new insatnces of derived classes from base class. 我想将Instance方法移至DataAccessor基类,并从基类创建派生类的新实例。 How to do that? 怎么做?
public class DataAccess : DataAccessor
{
public static DataAccess Instance
{
get
{
return new DataAccess();
}
}
}
public abstract class DataAccessor
{
}
public class Base<T> where T : new()
{
public static T Instance
{
get { return new T(); }
}
}
public class Derived : Base<Derived>
{
}
您是否考虑过抽象工厂模式 ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.