Organization / Organization of my classes / interfaces in folders? Without changing the namespace with the folder (Resharper: Namespace) = false)

I currently have a project and its size is increasing every day. This is the container for api that I provide.

Currently, I have fundamentally all my classes and all interfaces.

I shared my Enums, Contants, etc. into my own folders, but I don’t inherit the folder as part of the namespace, they are just containers to keep them in order.

I was wondering if anyone has any experience here?

Should I also share my interfaces in my own folder (without inheriting the folder as part of the namespace)

Should I also separate classes?

I also have classes that are children of other classes. Those. a class implements it as a property. Therefore, it will never be created outside. So I have to separate them even further and put (for example) a folder called "Products", and inside this folder I will have a class Product, and then my class item and other classes specific to Product?

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

I would like to hear some feedback.

thanks

+4
source share
1 answer

Such situations rarely arise during development. In fact, in most cases you have separate projects, and not one project with a large number of folders. Personally, I find the confusing project an obvious smell of code. If nothing else, your project will not compile so quickly because it compiles as a fragment, while individual projects can be compiled in parallel (more or less, it all depends on dependencies).

However, if you really want to save everything in one project, here I take it upon myself:

  • If there is something common to all elements of the project (eg, utility extension methods), I create a folder called Infrastructure , without forcing it does not use a namespace provider and to place there all the usual files.
  • I'm trying to separate the rest of the project based on behavior, not type. For example, you propose to separate enumerations and classes, but this seems to me wrong - if I have database objects that are either classes or enumerations, I would prefer to have a folder named Entities (and therefore the namespace MyProject.Entities ) , which contains both enumerations and classes in one place. (Note also that if you suddenly switch to a project called MyProject.Entities , you won’t have to change the namespace.)

To summarize, try grouping files by functionality, not by type.

+2
source

Source: https://habr.com/ru/post/1345517/


All Articles