Static method , Abstract method , Interface method comparision ?

Posted by programmerist on Stack Overflow See other posts from Stack Overflow or by programmerist
Published on 2010-04-15T06:56:25Z Indexed on 2010/04/15 7:03 UTC
Read the original article Hit count: 494

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about c#3.0