|
The total number of ancestors of a type (direct or indirect) in the inheritance hierarchy.
This metric counts all the super types of a given reference type.
It is an indication of how deeply embedded a type is in a given
inheritance hierarchy.
This metric is often confused with the
depth of inheritance hierarchy
metric proposed by Chidamber and Kemerer. In particular,
Patrick Smacchia's NDepend tool
defines depth of inheritance
to be the number of ancestors. Indeed, if the type hierarchy were a
tree, the two definitions coincide. However, in the presence of interfaces,
a type can have multiple immediate supertypes, and therefore there are multiple
paths to Object. The depth is the length of the longest such
path, whereas the present metric returns the number of types encountered on
any such path.
Pre-packaged Query
Query name = "Semmle/Metrics/Types/Inheritance/RefTypes that have many ancestors in the type hierarchy"
Reports types that have more than 10 ancestors, in decreasing order, as a bar chart.
from MetricRefType t, int d
where t.fromSource() and d = t.getNumberOfAncestors() and d > 10
select t, d order by d desc
.QL Source of Metric
This metric is defined in the class MetricRefType. It reads
as follows:
int getNumberOfAncestors() {
result = count(this.getASupertype+())
}
The + operator in the above definition stands for the transitive closure:
this.getASupertype() would just return the immediate ancestors of
this. By taking the transitive closure, we also get the indirect
ancestors.
References
Patrick Smacchia.
NDepend
(metrics exploration tool for .NET), 2007.
|