Skip to main content

Coupling Between Object Classes

Number of classes to which a class is coupled.

Two classes are coupled when methods declared in one class use methods or instance variables defined by the other class. The uses relationship can go either way: both use and used-by relationships are taken into account, but only once.

Multiple accesses to the same class are counted as one access. Only method calls and variable references are counted.

A high CBO is undesirable. Excessive coupling between object classes is detrimental to modular design and prevents reuse. The more independent a class is, the easier it is to reuse it in another application. To improve modularity and promote encapsulation, inter-object class couples should be kept to a minimum. The larger the number of couples, the higher the sensitivity to changes in other parts of the design, and therefore maintenance is more difficult. A high coupling has been found to indicate fault-proneness.

A recommended CBO is 12 or less.

Additional resources:

Config Example​

dart_code_metrics:
...
metrics:
...
coupling-between-object-classes: 12
...