Contents > 8 Defining Custom Design Metrics and Rules > 8.1 Definition of Metrics > 8.1.8 Subelements

8.1.8 Subelements

The subelements procedure allows for a simple way to count all elements, or elements of selected types, that a given model element owns directly or indirectly.

For example, to count for a package the number of operations that are defined in interfaces, classes (including inner classes), subsystems etc. of the package and all of its subpackages and subsystems, sub-subpackages and so on, at any level, we can simply write:

<metric name="NumOps_tc" domain="package"> 
  <description>The number of operations defined in the package, its 
        subpackages, etc.</description>
  <subelements target="operation"/>
</set>
One could achieve the same result with projections, however, it would require the definition of several helper metrics to gather operations in interfaces, classes, etc. separately and take the sum of these metrics.

The subelements procedure takes the following, optional, attributes: