I was always using interfgaces similarly to abstract classes - just to make sure all objects will have consistent external methods etc.
But from MSDN, I do not get that:
interface ISampleInterface
{
void SampleMethod();
}
class ImplementationClass : ISampleInterface
{
// Explicit interface member implementation:
void ISampleInterface.SampleMethod()
{
// Method implementation.
}
static void Main()
{
// Declare an interface instance.
ISampleInterface obj = new ImplementationClass();
// Call the member.
obj.SampleMethod();
}
}
Why there is explicitly mentioned interface name in the method declaration and why it does not work without it? Also why is the interface being instantionated, shouldn't be just instance of class implementing it?