Contents > 8 Defining Custom Design Metrics and Rules > 8.1 Definition of Metrics > 8.1.6 Connected Components

8.1.6 Connected Components

The connectedcomponents procedure is used to count the connected components in a graph. The procedure uses element sets to obtain information about nodes and edges of the graph.

The procedure has four attributes:

For example, to calculate the number of inheritance hierarchies among the classes in a package, we define three element sets (see Section 8.2 "Definition of Sets"): We can then calculate the number of connected components in the inheritance hierarchy as follows:
<metric name="InhHierarchies" domain="package"> 
  <description>The number of inheritance hierarchies.</description>
  <connectedcomponents set="Classes" nodes="Parents+Children" />
The following example uses an undirected graph and only counts connected components with at least two nodes (i.e., ignoring isolated classes that do not participate in any inheritance relationship):
<metric name="InhHierarchies" domain="package"> 
  <description>The number of non-trivial inheritance hierarchies.</description>
  <connectedcomponents set="Classes" nodes="Parents" undirected="true" 
     minnodes="2" />