Class ComponentDependencyMetrics


public final class ComponentDependencyMetrics
extends java.lang.Object
Calculates architecture metrics as defined by Robert C. Martin in his book "Clean architecture : a craftsman's guide to software structure and design".

These metrics are calculated following these definitions for each component:
  • Efferent Coupling (Ce): The number of outgoing dependencies to any other component
  • Afferent Coupling (Ca): The number of incoming dependencies from any other component
  • Instability (I): Ce / (Ca + Ce), i.e. the relationship of outgoing dependencies to all dependencies
  • Abstractness (A): num(abstract_classes) / num(all_classes) in the component
  • Distance from Main Sequence (D): | A + I - 1 |, i.e. the normalized distance from the ideal line between (A=1, I=0) and (A=0, I=1)

As an example take

 A -> B -> C
 D -> B
Then Ce(B) = 1, Ca(B) = 2, I(B) = 1 / (1 + 2) = 0.33. Assume 1/3 of the classes in the component would be abstract, then A(B) = 0.33, thus D(B) = | 0.33 + 0.33 - 1 | = 0.33.

Martin's thesis about these metrics is, that the more stable (low I value) a component gets, the higher the Abstractness (A value) should be (thus the Distance from the Main Sequence).

Note: As an adjustment to the original definitions of these metrics we only consider public classes to calculate the abstractness of a component. The background is, that these metrics analyse the maintainability of components in relation to their dependencies. Internals of a component (non-public classes) do not influence the coupling of two components, since there cannot be any dependencies to these components from the outside. Thus they can be freely modified, no matter how many incoming dependencies there are, or if they are abstract or not.