This metric measures the number of classes in each file.

There are advantages and disadvantages associated with defining multiple classes in the same file. However, if you define unrelated classes in one file then the resulting module API is difficult for other developers to understand and use.

The disadvantages of putting multiple classes in the same file include:

Sometimes there are advantages of putting multiple classes in the same file, for example:

Each module should have a single, well-defined role. Consequently, only logically-related classes should be grouped together in the same file. If your code defines unrelated classes in the same file then you should refactor the code and create new files, each containing logically related classes.

  • Python: Class Definitions.
  • M. Fowler, Refactoring. Addison-Wesley, 1999.
  • Wikipedia: Code refactoring.