Having too many class definitions in Java can be unreadable

[nz_btn text="Software Agility" link="http://casthighlight.wpengine.com/software-agility/" icon="icon-dashboard" color="black" shape="rounded"][nz_btn text="Code Readability" link="http://casthighlight.wpengine.com/category/product/indicators-methodology/code-insights/software-agility/code-readability/" icon="icon-code" color="black" shape="rounded" type="ghost" hover_ghost="screen"]

Avoid too many classes in the same file

This code insight counts one occurrence each time a source file is found with multiple class definitions. Developers can spend time looking for a class in a file if multiple classes are there. Converserly, it is straightforward when the file contains only the searched class.

CAST recommendations

Ideally, for readability purpose, one source file contains one class.

References

https://dzone.com/articles/why-single-java-source-file-can-not-have-more-than https://stackoverflow.com/questions/968347/can-a-java-file-have-more-than-one-class

About CAST and Highlight’s Code Insights

Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.
[nz_btn text="See features" link="http://casthighlight.wpengine.com/outputs-analytics/" icon="icon-stats" color="black" shape="rounded"][nz_btn text="How it works" link="http://casthighlight.wpengine.com/how-it-works/" icon="icon-cog" color="black" shape="rounded" type="ghost"] c
For reference only. For the complete details please refer the original article
https://doc.casthighlight.com/alt_classdefinitions-avoid-too-many-classes-java/
Have more questions? Submit a request

Comments

Powered by Zendesk