I have been trying to understand what interfaces actually are, and in theory I have digested the definition very well. But when it comes to actually using them, some questions come to my mind.
Most resources define interface this way:
“An interface is a contract between itself and any class that implements it. This contract states that any class that implements the interface will implement the interface's properties, methods and/or events. An interface contains no implementation, only the signatures of the functionality the interface provides. An interface can contain signatures of methods, properties, indexers & events.”
This is very easy to understand, but my question is that if interfaces are (according to this definition) some sort of a blueprint or contract between themselves and classes, what would actually happen if I define this interface,
interface ITest {
int SomeTestVariable { set; get;}
int SomeTestMethod ();
}
make a class that implements this interface as well as all its methods
class Test: ITest {
int SomeTestvariable { set; get;}
int SomeTestMethod () {
return 1;
}
}
and after all the methods and properties have been implemented then I remove it.
class Test {
int SomeTestvariable { set; get;}
int SomeTestMethod () {
return 1;
}
}
Now I must have a class which has used this blueprint or contract. So what would be difference between writing this blueprint on a piece of paper and making an interface?