|
Abstractness measures the proportion of abstract types in a package relative to the total number of types in that package.
A highly abstract package (where the metric value is close 1)
that is furthermore
unstable is likely to be useless: the
class hierarchy has been over-engineered, and all those
abstract types are not heavily used.
One should try to design packages that are abstract in
proportion to their incoming dependencies, and concrete in
proportion to their outgoing dependencies. That way, making
changes is likely to be easy. See
this
excellent summary of Robert C. Martin's work
for further discussion of these metrics and their use.
Distance of a Package from Main Line is a combined metric that captures the balance
between abstractness (this page) and
instability.
Pre-packaged Queries
Query name = "Semmle/Metrics/Packages/Packages that have abstractness > 0.2"
Reports packages in source where the abstractness value is greater
than 0.2, in decreasing order of abstractness as a bar chart.
from MetricPackage p, float c
where p.fromSource() and c = p.abstractness() and c > 0.20
select p, c order by c desc
Query name = "Semmle/Metrics/Packages/Concrete packages"
Reports packages in source that are completely concrete,
with abstractness=0.
from MetricPackage p, float c
where p.fromSource() and c = p.abstractness() and c = 0
select p, c order by c desc
.QL Source of Metric
This metric is defined in MetricPackage. Its definition
is a direct translation of the formula:
float abstractness() {
exists ( int i, int j | i = count(RefType t | t.getPackage() = this) and
j = count(RefType t | t.getPackage() = this and
t.hasModifier("abstract")) and
result = j / i and i > 0 )
}
References
Robert C. Martin. Object-Oriented Design Metrics Ensure Robust Software. January 6, 2003.
Robert C. Martin. OO Design Quality Metrics. October 24, 1994.
Robert C. Martin.
Agile Software Development, Principles, Patterns and Practices.
Addison Wesley, 2002.
Bill Venners.
How Useful are Code Metrics?
Artima Developer, April 26, 2006.
Wikipedia.
Software Package Metrics
.
2007.
|