Contents > 8 Defining Custom Design Metrics and Rules > 8.1 Definition of Metrics
8.1 Definition of Metrics
A metric is defined with an XML element as follows:
<metric name="metricname" domain="metricdomain" category="metriccategory"
<description>Description of the metric.</description>
<'metric definition' ...>
The attributes in the opening "metric" tag are as follows:
Note that metrics for one domain must have unique names (i.e., you
cannot define two metrics named "NumOps" for classes). You can have
metrics of the same name for different domains (e.g., a metric
"NumOps" for classes, and a metric "NumOps" for interfaces).
- name (required): the name of the metric. The metric names
serve as column names in the output tables, and are also used to
reference the metrics.
- domain (required): the type of element for which the
metric is defined (e.g., package, class, operation).
- category (optional): describes the structural property
the metric measures, e.g., "size", "export coupling", "cohesion", etc.
There is no preconceived classification of categories in SDMetrics,
you can define any categories you deem fit. This attribute only serves
documentation purposes and does not impact the calculation of the metric
in any way.
- internal (optional): indicates if the metric is
internal. An internal metric is not shown in the output tables. It is rather
a "helper" metric that is used to define some other metrics, but
by itself is probably not useful. Set the attribute value to "true" to
mark a metric as internal. When omitted, the attribute defaults to
- inheritable (optional): indicates if the metric should
also be defined for all subtypes of the "domain" element type.
When you set the attribute value to "true", all direct and indirect
subtypes of the domain "inherit" the metric definition, and the metric
will be calculated for all subtypes, too. When omitted or set to "false",
the metric definition is not passed on to subtypes.
Following the metric tag is an optional description of the metric,
which will be shown in the measurement catalog (see Section 4.13 "The View 'Catalog'").
Section 8.6 "Writing Descriptions" explains how to write metric descriptions.
Following the description is an XML element that defines the
calculation procedure for the metric. We describe each calculation
procedure in detail in the following subsections.
8.1.2 Compound Metrics
8.1.3 Attribute Value
8.1.6 Connected Components
8.1.7 Value Filter
|Section 8 "Defining Custom Design Metrics and Rules"||Contents||Section 8.1.1 "Projection"|