Well, in client-server architecture, an
Interface is an contract (i.e an Agreement) between client and server which is implemented on server side and tells the client that what it contains. The examples can be
RMI
.
One interface can be implemented by more than one classes, that's why you can have
multiple kind of instance of that interface.
For example, in .NET
object
is base class of all of the other classes, even user-defined as well.
This object class implement the interface that has these 4 methods like Equals(), ToString(), GetType() and GetHashCode(). You can find more info
here[
^].
Let's talk about
ToString(). You may find this method each and every damn objects in your application. For example, you can get the String format of int, float, double and/or user defined objects.
But the question is how to distinguish which ToString() works for int, which for double and which for float?
So the answer is these wrapper i.e
Int, Double, Float etc
class has the implement of the object interface and each may have the different implement for ToString().
In this kind of situation you need an interface. Let's say in you application, 5 classes has almost same methods but works differently so you can create one interface, implement by these 5 classes and can use it.
Some examples,
http://msdn.microsoft.com/en-us/library/87d83y5b.aspx[
^]
[
^]
http://www.onlinebuff.com/article_implementing-interface-in-c-with-an-example_18.html[
^]
http://www.c-sharpcorner.com/UploadFile/sekarbalag/interface-best-example-in-csharp/[
^]
http://www.c-sharpcorner.com/UploadFile/sekarbalag/interface-best-example-in-csharp/[
^]
Hope this would help you.
-KR