I've been attempting to figure out what interfaces are, and in principle, I've absorbed the term rather well. However, when it comes to actually employing them, I have some concerns.
The following is how most resources define interface:
"An interface is a contract that exists between the interface and any class that implements it." Any class that implements the interface must implement the interface's properties, methods, and/or events, according to this contract. There is no implementation in an interface; only the signatures of the functionality it provides. Method signatures, attributes, indexers, and events can all be found in an interface."
This is really clear, but my issue is: if interfaces are (according to this definition) a kind of blueprint or contract between themselves and classes, what happens if I define this interface, for example?
interface ITest {
int SomeTestVariable { set; get;}
int SomeTestMethod ();
}
Create a class that implements both the interface and all of its methods.
class Test: ITest {
int SomeTestvariable { set; get;}
int SomeTestMethod () {
return 1;
}
}
I remove it once all of the methods and attributes have been implemented.
class Test {
int SomeTestvariable { set; get;}
int SomeTestMethod () {
return 1;
}
}
Now I need to find a class that's used this blueprint or contract. So, what's the difference between drawing this blueprint on paper and creating an interface?