What is an interface?
When to use interface?
purpose of interface?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Debadatta MishraRank #1,423 · 1.1K reputationPosted Sep 22, 2013, 7:36 AM EDT
Interfaces must be used in an application where there can be multiple implementations and you want to provide a good level of abstraction. If you provide an interface as a functional protocol, others have to provide the actual implementations to respect your functional protocol.
Think about a situation, you want to validate an object based upon certain rules, but the validations may be changed in different situations. In this case you have to provide an interface. I provide below an example.
//Situation 1
Validator validator = new Situation1ValidatorImpl1();
validator.validate(yourObject);
//Situation 2
Validator validator = new Situation2ValidatorImpl2();
validator.validate(yourObject);
//Situation 3
Validator validator = new Situation3ValidatorImpl3();
validator.validate(yourObject);
In the above case Validator is an Interface where as Situation1ValidatorImpl1,Situation2ValidatorImpl2,Situation3ValidatorImpl3 are different implementations in different context. You can also mark that the code "validator.validate(yourObject);" remains static through out your application.
The primary objective of usage of Interface is to provide a level of abstraction in your application.
Jignesh TrivediRank #16 · 50.3K reputationPosted Sep 22, 2013, 8:15 PM EDT
hi
Please refer following link it might help to understand interface
http://msdn.microsoft.com/en-us/library/vstudio/ms173156.aspx
http://msdn.microsoft.com/en-us/library/87d83y5b.aspx
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Sep 22, 2013, 8:34 PM EDT
http://www.c-sharpcorner.com/UploadFile/3d39b4/interface-in-C-Sharp-part-1/