views:

95

answers:

1

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?

First Type Usage

 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;
        }

Second Type Usage

Also i can write it below codes:

public class GenAccessor
{
     public Static bool Save()
     { 
     }

     public Static bool Update()
     {
     }

     public Static bool Delete()
     {
     }
}

Third Type Usage

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?

+2  A: 

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.

Fakrudeen
Can you give some details?
programmerist
I agree with this explanation. And to answer directly to your question I would always prefer your first approach.
SoMoS
Why do you prefer first approach Somos?
programmerist