An interface is a contract. It tells others that your class supports certain methods - it doesn't say how they are implemented, only that those methods are present. What this means, in practice, is that you can accomplish the same thing in many different ways; absolutely invaluable if you want to use something like Inversion of Control (IoC).
As an example, if you want to use the using pattern in C# then your class must implement
IDisposable
. Behind the scenes, the compiler translates the using block into the following:
SomeClass someClass = null;
try
{
someClass = new SomeClass();
}
finally
{
((IDisposable)someClass).Dispose();
}
There you see someClass being cast to
IDisposable
which allows the application to call
Dispose
.