views:

61

answers:

3

i"m new to interfaces

i have this code example :

public class DALF
{
   public  class Car
    {

        public int AddEdit(int? CarId, string Name)
        {
          ....
        }


        public DataTable Get(int? CarId)
        {
           .....

            return CarD.Get(obj);
        }

    }

    public class Worker
    {
           public static int AddEdit(int? WorkerId, string Name)
        {
          ....
        }

        public DataTable Get(int? WorkerId)
        {
         .....

            return carD.Get(obj);
        }

    }
}

How can i implement this calss as interface?

+1  A: 

Are you sure you only have static classes and methods? Interfaces are not relevent in this case.

More info here: http://stackoverflow.com/questions/259026/why-doesnt-c-allow-static-methods-to-implement-an-interface

o.k.w
Hmm, I'd want to phrase that differently. Its certainly clear that defining an interface containing statics makes little senses. Somewhat less clear that implementing an interface with statics is wrong though it's understandable (if my reading of the questions on the subject is right) why one might choose to not to allow it in a language implementation. Either way, the question needs to be expanded upon if a sensible answer is required
Murph
@Murph, you have a point there:P
o.k.w
+2  A: 
public interface IYourName
{
    int AddEdit(int? id, string name);
    DataTable Get(int? id);
}

public class DALF
{
   public class Car : IYourName
    {
        public int AddEdit(int? CarId, string Name)
        {
            //....
        }

        public DataTable Get(int? CarId)
        {
            //.....
            return CarD.Get(obj);
        }

    }

    public class Worker : IYourName
    {
        public int AddEdit(int? WorkerId, string Name)
        {
            //....
        }

        public DataTable Get(int? WorkerId)
        {
            //.....
            return carD.Get(obj);
        }
    }
}
Maximilian Mayerl
hi this is not what i mean , i want class implement the DALF
Yan
You want what? Your DALF class does nothing, it just contains sub classes...? So no interface there.
Maximilian Mayerl
+3  A: 

No offense, but I would suggest you read a few basic tutorials about OO. It sounds to me that you do not fully understand what an interface does or how inheritance works.


DISCLAIMER:

I know that this answer is not a solution to the question at hand. But our business here is to help people. And answering this question won't help avi, since his question (as far as I can understand) is based on a poor understanding of basic concepts of OO.

roosteronacid