Declaring interface in the same file as the base class, is it a good practice?

Posted by Louis Rhys on Programmers See other posts from Programmers or by Louis Rhys
Published on 2012-09-11T11:33:42Z Indexed on 2012/09/11 15:49 UTC
Read the original article Hit count: 281

Filed under:
|
|
|

To be interchangable and testable, normally services with logic needs to have interface, e.g.

public class FooService: IFooService 
{ ... }

Design-wise, I agree with this, but one of the things that bothers me with this approach is that for one service you will need to declare two things (the class and the interface), and in our team, normally two files (one for the class and one for the interface). Another discomfort is the difficulty in navigation because using "Go to definition" in IDE (VS2010) will point to the interface (since other classes refer to the interface), not the actual class.

I was thinking that writing IFooService in the same file as FooService will reduce the above weirdness. After all, IFooService and FooService are very related. Is this a good practice? Is there a good reason that IFooService must be located in its own file?

© Programmers or respective owner

Related posts about c#

Related posts about .NET