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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sanjeeb LenkaPosted Sep 23, 2013, 12:34 AM
http://www.c-sharpcorner.com/UploadFile/3d39b4/interface-in-C-Sharp-part-1/
Jignesh TrivediPosted Sep 23, 2013, 12:15 AM
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
Debadatta MishraPosted Sep 22, 2013, 11:36 AM
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.