0

I have written a class library with a class and an interface for the class.

At the moment the class is private and the interface is public.

If I import the dll for the class library into a console app I know that I will need to instantiate the interface like this:

IInterface iinterface = new Class();

But for that to work the Class will have to be publicly accessible too. I understand why you would want to code against the interface rather than the class but should I be giving a third party access to the class as well as the interface?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
markp3rry
  • 724
  • 10
  • 26

1 Answers1

4

Your interface actually provides a contract, for third party library, you expect the user to code against your interface not to use your class. If you want the third party user to have access to your class then you should make it public.

Habib
  • 219,104
  • 29
  • 407
  • 436
  • So what syntax would you write to code against the interface without creating it as a new instance of class? This is what's confusing me. – markp3rry Feb 20 '13 at 11:51
  • If you are exposing your interface from the library then the user of your library would implement that interface in his/her class. Here is a very good discussion about it http://stackoverflow.com/questions/4456424/what-do-programmers-mean-when-they-say-code-against-an-interface-not-an-objec – Habib Feb 20 '13 at 11:53
  • @markp3rry, you are welcome, you may as well see this : http://stackoverflow.com/questions/383947/what-does-it-mean-to-program-to-an-interface – Habib Feb 20 '13 at 11:58