Organizing classes via refactoring
It’s not uncommon for solutions to have organizational challenges such as misnamed files or types existing in the wrong file or namespace.
These problems may seem small, but they can make it harder for developers to find the code they’re looking for – particularly when first joining the project.
Let’s look at a few refactorings that help developers navigate code more easily.
Moving classes to individual files
One common mistake I’ve seen teams make is putting multiple types inside of the same file. Usually, a file starts with a single class or interface and then a developer decides to add a related type. Instead of putting the new type in a file of its own, the class gets added to the existing file. Once this happens for a few small classes, it tends to snowball after that with developers continuing to add new types to the file as time goes on.
Types
If you’re not familiar with the use of...