Reputation: 2966
When I choose these methods? I can not decide which one I must prefer or when will i use one of them? which one give best performance?
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;
}
}
Also I can write it below codes:
public class GenAccessor
{
public Static bool Save()
{
}
public Static bool Update()
{
}
public Static bool Delete()
{
}
}
Also I can write it below codes:
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)
{
}
}
I can use first one below usage:
GenAccessor gen = New GenAccessor();
gen.Save();
I can use second one below usage:
GenAccessor.Save();
Which one do you prefer? When will I use them? which time i need override method? which time I need static method?
Upvotes: 2
Views: 263
Reputation:
static methods are for methods which are independent of object state. Typically I would use them for utility methods and pure mathematical kind of functions. e.g. computeAverage(int[] values);
abstract/interface methods are pretty much the same thing. interface methods have the feel of pure contract. abstract methods are more version tolerant. If you have a contract and it can possibly have different implementations I would go with these.
static methods are more performant because they don't need to do virtual table lookup.
Upvotes: 3