Due to test-driven development, one ends up with many classes doing just one thing. It is quite a headache just to see where such classes would be placed inside the folder structure.
First of all, is it considered a bad-pattern, to put related classes in the same file?
Any suggestion on what one uses in actual-production environments?
6
Generally, you should put one class in one file. That way it is easy to find the pertinent code when making changes. I think that it would be more of a headache to have to try to remember how the classes were organized when looking for the code that I am trying follow. You aren’t creating these files for the computer but for the future developer (it might be you) that is going to be trying to find some bug or add a new feature. And files make that easier to do because A.class
is an easier to look for than Stuff.class
.
If you create a directory structure that groups similar classes together, that can reduce some of your headache.
In languages that support it, why not use namespaces? That should make it clear what the organization is, regardless of the folder structure.