When browsing ASP.NET MVC source code in codeplex, I found it is common to have a class explicitly implementing interface. The explicitly implemented method/property then in
sample for reason 1:
public interface IFoo
{
void method1();
void method2();
}
public class Foo : IFoo
{
// you can't declare explicit implemented method as public
void IFoo.method1()
{
}
public void method2()
{
}
private void test()
{
var foo = new Foo();
foo.method1(); //ERROR: not accessible because foo is object instance
method1(); //ERROR: not accessible because foo is object instance
foo.method2(); //OK
method2(); //OK
IFoo ifoo = new Foo();
ifoo.method1(); //OK, because ifoo declared as interface
ifoo.method2(); //OK
}
}