This metric measures the inheritance depth of a class.

Whilst inheritance provides an avenue for code reuse, overly-deep class hierarchies can become a maintenance headache. Classes that inherit from many other classes can be brittle and hard to understand, because they depend on all of the classes further up the hierarchy. Conversely, changes to classes nearer the root of the hierarchy become harder and harder to make without breaking the descendants. In extreme cases, where the design of the hierarchy is seriously inappropriate, the class at the top of the hierarchy can become a 'blob' class: a storage point for anything that might be needed by one of its descendants. This is a key indicator that some serious refactoring is needed.

As with many metrics, a high inheritance depth should be seen as an indicator that something is amiss, but further investigation will be needed to clarify the cause of the problem. Here are two possibilities:

In languages that support it (such as C++), this situation can be modeled somewhat more effectively using multiple inheritance, but an altogether better approach is to use a component-based architecture (i.e. composition).

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