当我选择这些方法时?我不能决定我应该选择哪一个,或者我什么时候使用其中一个?哪一个性能最好?
第一种类型用法
public abstract class _AccessorForSQL
{
public virtual bool Save(string sp, ListDictionary ld, CommandType cmdType);
public virtual bool Update();
public virtual bool Delete();
public virtual DataSet Select();
}
class GenAccessor : _AccessorForSQL
{
DataSet ds;
DataTable dt;
public override bool Save(string sp, ListDictionary ld, CommandType cmdType)
{
}
public override bool Update()
{
return true;
}
public override bool Delete()
{
return true;
}
public override DataSet Select()
{
DataSet dst = new DataSet();
return dst;
}
}
第二种类型的用法
我也可以写下面的代码:
public class GenAccessor
{
public Static bool Save()
{
}
public Static bool Update()
{
}
public Static bool Delete()
{
}
}
第三类用途
我也可以写下面的代码:
public interface IAccessorForSQL
{
bool Delete();
bool Save(string sp, ListDictionary ld, CommandType cmdType);
DataSet Select();
bool Update();
}
public class _AccessorForSQL : IAccessorForSQL
{
private DataSet ds;
private DataTable dt;
public virtual bool Save(string sp, ListDictionary ld, CommandType cmdType)
{
}
}
我可以使用下面的第一个用法:
GenAccessor gen = New GenAccessor();
gen.Save();
我可以使用下面的第二种用法:
GenAccessor.Save();
你喜欢哪一个?我什么时候用?我什么时候需要覆盖方法?我什么时候需要静态方法?