Contents > 8 Defining Custom Design Metrics and Rules > 8.3 Definition of Design Rules > 8.3.5 Element Comparison for Rules

8.3.5 Element Comparison for Rules

The compare procedure for rules performs a comparison of model elements, as described in Section 8.1.8 "Element Comparisons", and reports all model elements that match the comparison criterion.

As an example for an application of the compare procedure in the context of rules, we consider the Stable Dependencies Principle (SDP) [Mar03]. The SDP says that the instability (ratio of efferent couplings to total couplings) of a package should be larger than the instability of the packages that it depends on. Assume we already have defined the instability metric I for packages, and the set DepPackages of packages that a given package depends on. We can then define a rule reporting violations of the SDP as follows:

<rule name="SDP" domain="package" category="Style" severity="2-med">
  <description>Stable dependencies principle: Instability of a package 
   should be larger than that of the packages it depends on.</description>
  <compare term="I" set="DepPackages" with="I" comp="term<with" 
   value="qualifiedname(self)" />
</rule>
This compares the value of the I metric for the current package to the I values of the packages in DepPackages, reporting all packages with larger values.

In the context of rules, the report_element attribute is not allowed, and the compare procedure supports two additional attributes: