I browsed the internet for an answer to this question and the best I could find was:
“The primary benefit of a class per file is for source control and concurrent access: Why deal with the inevitable human error of code merges if each developer is really dealing with the separate classes.”
In my case there are several really small classes that seem like they can go into one file or be separated. As a personal style it seems best to put each class into separate file. This way I can easily see/find all the classes through solution explorer.
On the other hand it seems more like a stylistic argument, since I couldn’t find any evidence that it actually improves performance. I could also use VS diagramming tool to create a nice diagram for all the classes in a module.
So some possible guidelines for development team that can come out of this are:
- Allow including several classes in file only if each class is max of 10 lines of code.
- Classes in the same file must belong to the same Module (DDD Module)
- Enums should go in .cs file that uses them. If there are several classes that use enum – pick one.
Found another good reason for keeping classes in separate files:
“Also you’ll find many errors/diagnostics are reported via file name (“Error in Myclass.cpp, line 22″) and it helps if there’s a one-to-one correspondence between files and classes. ”