将我的类/接口排列/组织到文件夹中?不更改文件夹的命名空间(Resharper:命名空间提供程序 = false)

发布于 2024-10-28 04:28:09 字数 432 浏览 0 评论 0原文

我目前有一个项目,并且其规模每天都在增加。它是我提供的 api 的容器。

目前,我的所有类和所有接口都在根目录中。

我已将枚举、常量等分离到它们自己的文件夹中,但我不会继承该文件夹作为命名空间的一部分,它们只是保持整洁的容器。

我想知道有人有这里的经验吗?

我是否也应该将我的接口分离到它们自己的文件夹中(不继承该文件夹作为命名空间的一部分)

我也应该将我的类分离吗?

我也有一些类是其他类的子类..即类将其实现为属性。因此它永远不会在外部实例化。那么我是否应该进一步将它们分开并放置(例如)一个名为“Products”的文件夹,在这个文件夹中我将拥有我的产品类,然后是我的项目类和其他特定于产品的类?

同样,使用文件夹作为分隔的手段,而不是继承文件夹名称作为命名空间的一部分。

我很想听到一些反馈。

谢谢

I currently have a project and its increasing in size everyday. Its a container for an api i am providing.

I currently have in the root all my classes and all interfaces.

I have separated my Enums, Contants, etc into their own folders but i don't inherit the folder as part of the namespace they are just containers to keep them tidy.

I was wondering if anybody has any experience here?

Should i separate my interfaces into their own folder too (not inheriting the folder as part of namespace)

Should i separate my classes also?

I also have classes that are children of other classes .. ie a class implements it as a property. Hence it would never be instantiated outside. So should I separate them even further and put (for example) a folder called "Products" and inside this folder i would have my Product class and then my item class and other classes that are specific to Product?

Again, using the folder as a means of separating and not inheriting the folder name as part of the namespace.

I would love to hear some feedback.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清晨说晚安 2024-11-04 04:28:09

这种情况在开发中很少出现。事实上,在大多数情况下,您最终会拥有单独的项目,而不是具有大量文件夹的单个项目。就我个人而言,我认为复杂的项目有明显的代码味道。如果不出意外,您的项目将不会编译得那么快,因为它被编译为一个块,而单独的项目可以并行编译(或多或少 - 它都受到依赖关系的影响)。

也就是说,如果您确实想将所有内容保留在一个项目中,那么我的看法是:

  • 如果项目的所有元素都有共同点(例如,有用的扩展方法),我会创建一个名为 Infrastruct 的文件夹>,确保它不是名称空间提供者并将所有常见内容放在那里。
  • 我尝试根据行为而不是类型来区分项目的其余部分。例如,您建议将枚举和类分开,但这对我来说似乎是错误的 - 如果我有属于类或枚举的数据库实体,我宁愿有一个名为 Entities 的文件夹(因此MyProject.Entities 的命名空间),其中在单个位置包含枚举和类。 (另请注意,如果您突然将其迁移到名为 MyProject.Entities 的项目,则无需更改名称空间。)

总而言之 - 尝试按功能而不是按类型对文件进行分组。

These kinds of situations rarely arise in development. In actual fact, in most cases you end up having separate projects rather than a single project with lots and lots of folders. Personally I consider a convoluted project an obvious code smell. If nothing else, your project won't compile as quickly because it gets compiled as a chunk, whereas separate projects can be compiled in parallel (more or less - it's all influenced by dependencies).

That said, if you really want to keep everything in one project, here's my take on it:

  • If something is common to all elements of the project (e.g., useful extension methods), I make a folder called Infrastructure, ensure it's not a namespace provider and put all common stuff there.
  • The rest of the project I try to separate on the basis of behavior, not type. For example, you suggest having enums and classes separate, but that just seems wrong to me - if I have database entities that are either classes or enums, I would rather have a folder called Entities (and thus a namespace of MyProject.Entities) that contains both the enums and the classes in a single location. (Note also that if you were to suddenly migrate this to a project called MyProject.Entities you wouldn't have to change your namespaces.)

To sum up - try grouping files by functionality, not by type.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文