I recently seen some C# code where the interface declaration and implementation where in the same file, like this
namespace MyNameSpace.Foo
{
public interface IFoo{
void DoThis();
}
public class Foo : IFoo {
public void DoThis();
}
}
At first glance it seems all wrong to have declaration and implementation in the same file, but there are practical benefits. e.g. When you Go To Definition in Visual Studio the interface and implementation are there in the same file. This approach does not prohibit you from having other implementations of the interface, such as may be needed for unit testing. For interfaces that will only have one implementation I think this can be a pragmatic approach.
Good or bad idea?
Extending the question:
How do people use Visual Studio to navigate to an implementation when you have an interface reference IFoo myFoo = FooFactory.getFoo(MY_FOO); If I right click on IFoo and select Go To Definition I can get the interface declaration. Is there a way for me to get the list of implementations of IFoo as that's what I'm really interested in getting to.