Clean-Code-Notes icon indicating copy to clipboard operation
Clean-Code-Notes copied to clipboard

Class and file organization

Open bstordrup opened this issue 5 years ago • 2 comments

There are a lot of information about keeping functions short, not too many parameters for functions and keeping classes small and dedicated specific purpose.

But what about the file-wise organization of classes? What is considered clean code in that aspect? Is it having one class per file? Or is it allowed to have multiple classes in the same file if they are in the same area. And what about languages that can split the interface definition into a different file than the implementation (like C++ with .h and .cpp files)?

bstordrup avatar Dec 03 '20 07:12 bstordrup

Thanks for that

sumitanwar avatar Jan 09 '23 17:01 sumitanwar

thank you

Vy89xxxx avatar Jan 11 '23 07:01 Vy89xxxx

In my experience, keeping only one class per file is the best. This helps to have responsibility separation and allows new developers to get familiar with the codebase quickly. About the languages that allow a headers file and a source file, the best is also to keep only one class per group.

JuanCrg90 avatar Jan 11 '23 19:01 JuanCrg90