IDisposable is just one interface, but the question might be generalized "Why should I implement an interface when I can simply implement methods?". Here is another example which might shed some light: it matters when it comes to consuming the classes.
interface IAnimal
{
void PutInZoo(Zoo);
}
class Cat: IAnimal
{
public void PutInZoo(Zoo theZoo);
}
class Fish
{
public void PutInZoo(Zoo theZoo);
}
class Zoo
{
public void PutInZoo(IAnimal animal)
{
animal.PutInZoo(this);
}
public Zoo()
{
this.PutInZoo(new Cat()); // Ok
this.PutInZoo(new Fish()); // Nope, Fish doesn't implement IAnimal
}
}
The most prominent side effect of implementing an interface, aside from compilation errors, is that if the interface changes you must abide to it.
In this example, if IAnimal
changes its definition and PutInZoo
is renamed to FreeFromZoo
, Fish
would still compile (and probably break its consumers) but Dog
won't: it no longer implements IAnimal
.