说明:将共用部分抽成一个接口或者抽象方法. 比如我们操作数据库 增加 修改 删除定义一个抽象类。
类图:

代码:
public abstract class Database<T>
{
public abstract List<T> Select(int id);
public abstract int Add(T t);
public abstract bool Update(T t);
public abstract bool Delete(int id);
}
public class ModelADAL : Database<ModelA>
{
public override List<ModelA> Select(int id)
{
throw new NotImplementedException();
}
public override int Add(ModelA t)
{
throw new NotImplementedException();
}
public override bool Update(ModelA t)
{
throw new NotImplementedException();
}
public override bool Delete(int id)
{
throw new NotImplementedException();
}
}
public class ModelBDAL : Database<ModelB>
{
public override List<ModelB> Select(int id)
{
throw new NotImplementedException();
}
public override int Add(ModelB t)
{
throw new NotImplementedException();
}
public override bool Update(ModelB t)
{
throw new NotImplementedException();
}
public override bool Delete(int id)
{
throw new NotImplementedException();
}
}
public class ModelA
{
}
public class ModelB
{
}
浙公网安备 33010602011771号