1

I have an Interface like this:

namespace QuickRoutes.Model.Utilities
{
    public interface IRoutesManager
    {
        bool ImportRoute(Stream inputStream, string fileName);
        List<Route> GetAllRoutes();
        List<Route> GetAllRoutesForDate(DateTime from, DateTime to);
        void DeleteRoute(string routeName);
        void DeleteAllRoutes();

    }
}

and I want to access to i.e ImportRoute function from my Form but I cant access to this Function and an error occured like this: cannot create an instance of the abstract class or interface How can I access to these functions?

1
  • 2
    I think you need to learn OOPS concepts. Commented Jun 16, 2012 at 10:00

2 Answers 2

3

You need to have an implementation of the interface which defines the actual behaviour. The interface itself only declares the members - as you can see, there's no code there to say what to do.

Your Form can either create an instance of some implementation, or be given it - quite possibly only as an IRoutesManager, so that the form itself doesn't need to care about which implementation it's using.

Sign up to request clarification or add additional context in comments.

Comments

1

You never create instances of interfaces, interfaces are just contracts. What you would do is :-

public class MyRouteManager : IRoutesManager
{ 
    bool ImportRoute(Stream inputStream, string fileName)
    { code here etc etc } 
    List<Route> GetAllRoutes();
    List<Route> GetAllRoutesForDate(DateTime from, DateTime to);
    void DeleteRoute(string routeName);
    void DeleteAllRoutes();

}

You coudl also change the word interface to class if its a class you wish instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.