I have many models in my project that are unrelated to each other. I wanted to group them but I wonder what's better:

Folder/namespace per group

  • Group1.Constants, Group2.Constants
  • Group1.Models, Group2.Models
├── Models/
│   ├── Class1.cs
│   ├── Class2.cs
├── Constants/
│   ├── Constants1.cs
│   ├── Constants2.cs

Folder/namespace per type

  • Constants.Group1, Constants.Group2
  • Models.Group1, Models.Group2
├── Group1/
│   ├── Class1.cs
│   ├── Class2.cs

├── Group1/
│   ├── Constants1.cs
│   ├── Constants2.cs

Which is better and why?

Note: I don't want to put them in separate projects, as those types will be used only by 1 project.


1 Answer 1


There isn't necessarily a clearly superior solution here. Either approach may be perfectly fine.

A general piece of advice is that things that change together should be close together:

  • If you expect that you are more likely to change models and constants within a group together, the organizing your code by groups first is sensible.
  • If you expect that you are more likely to change only one type of code but across all groups, then you should organize by type first.

If in doubt, I'd first organize by group because you say that these groups are unrelated. This doesn't prevent you from also sharing some code across all groups, and organizing that shared code by type.

Not the answer you're looking for? Browse other questions tagged or ask your own question.