The computer could care less about the folder structure you concoct, so this question definitely falls under the category of code readability. As mentioned in this post about standards of code readability, friendly naming, consistency, and logical code separation are fundamental to the creation of readable code.
So, where does that leave us? The creation of files--and the creation of namespaces and file regions--should be consistent. The names should be understandable. And the code in each aggregate category should have something in common, as should be detailed in the category name. Ultimately, with readability, you're considering that your code might be inherited by another poor fellow, and that the naming standards that you've created might help that poor fellow (a "tourist developer", if you will) more easily navigate around in the madness.
That's a lot of talking, so let me get down to brass tacks. These are my rules, but I think they might be helpful to those who are looking to clean up their own code aquariums:
- Place one class (or one interface, enum, or struct)
in one file.
- The name of the class should be the
name of the file.
- Classes that inherit from the same base class should be in the same folder.
- If at all possible, a class should be in the same folder as the interface that that class implements.
- An interface should have the same name as the class, but should be prefixed with a capitalized "I". It's the only bit of coding advice I still respect from the Hungarians.
- The folder name should be a pluralized version of the base class. For example, if we're creating a bunch of Engines, Engine should be the base class name, Engines should be the folder name, and all of the classes that inherit from Engine should be in the Engines folder.
- The namespace structure should directly follow the folder structure. So, the namespace for a given set of Engines (example from above) should be placed into a namespace called Engines. If Engines is a subfolder of a subfolder, each subfolder should be its own sub-namespace, e.g. Project1.Subfolder1.Subfolder2.Engines.
- When you're dealing with partial classes that need to live in two separate folders (as one piece of the class is autogenerated), place the non-autogenerated class into a folder suffixed with Extensions. In the file, comment out the Extensions namespace like so:
namespace FatDish.Engines//.EngineExtensions { ...
When it comes to navigability, the first and second rule are key, as they directly aid in indicating to the "tourist developer" where any given piece of code resides.
That's all I can think of at the moment. It's more important that you're consistent in your conventions than it is that you adopt any particular form of conventionality. That will help other developers understand and consume your code at a quicker rate, and ensure that future developments in the project (written by folks other than yourself) stay within the same conventional, coherent bounds that you've established.
Hope this helps!