do接口属于自己的文件 [英] do interfaces belong in files of their own
问题描述
作为经验法则,我通常把类放在自己的文件中。视觉工作室似乎鼓励这个,但什么是适当的接口?
例如
实现接口Bar
public interface IBar
{
}
public class Foo:IBar
{
}
似乎很自然地将这些内容放在同一个文件中,直到另一个类实现了接口,但是将一个文件专用于2行代码似乎过多,但是正确。
什么是合适的?
我会将它们分成2个文件。我经常发现当他们不在自己的文件中时,类开始变得难以管理。
想象一下,在名为IBar.cs的文件中找到类Foo,反之亦然。 / p>
As as rule of thumb I generally put classes in a file of their own. Visual studio seems to encourage this but what is appropriate with regards to interfaces?
e.g.
I have Class Foo that implements interface Bar
public interface IBar
{
}
public class Foo : IBar
{
}
it seems natural to group these within the same file until another class implements the interface but to dedicate a file to 2 lines code seems excessive but correct.
What is appropriate?
I would split them into 2 files. I often found classes starting to go unmanageable when they are not in their own files.
Imagine trying to find class Foo in a file named IBar.cs or vice versa.
这篇关于do接口属于自己的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!