Class ComponentDependencyMetrics
java.lang.Object
com.tngtech.archunit.library.metrics.ComponentDependencyMetrics
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:
As an example take
Martin's thesis about these metrics is, that the more stable (low
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.
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.
-
Method Summary
Modifier and TypeMethodDescriptiondouble
getAbstractness
(String componentIdentifier) TheAbstractness (A)
of the components.int
getAfferentCoupling
(String componentIdentifier) TheAfferent Coupling (Ca)
of the components.int
getEfferentCoupling
(String componentIdentifier) TheEfferent Coupling (Ce)
of the components.double
getInstability
(String componentIdentifier) TheInstability (I)
of the components.double
getNormalizedDistanceFromMainSequence
(String componentIdentifier) TheNormalized Distance from Main Sequence (D)
of the components.
-
Method Details
-
getEfferentCoupling
TheEfferent Coupling (Ce)
of the components.- See Also:
-
getAfferentCoupling
TheAfferent Coupling (Ca)
of the components.- See Also:
-
getInstability
TheInstability (I)
of the components.- See Also:
-
getAbstractness
TheAbstractness (A)
of the components.- See Also:
-
getNormalizedDistanceFromMainSequence
@PublicAPI(usage=ACCESS) public double getNormalizedDistanceFromMainSequence(String componentIdentifier) TheNormalized Distance from Main Sequence (D)
of the components.- See Also:
-