Contents > 8 Defining Custom Design Metrics and Rules > 8.2 Definition of Sets

8.2 Definition of Sets

For a UML model element, you can define any number of sets. Sets are useful to simplify the definition of metrics and rules (as we already have seen in the previous section), and to define metrics with set semantics. For instance, there can be multiple associations between two classes. If you want a metric not to account for each association separately, but just the fact that there is at least one association, you can accomplish this with sets.

We distinguish two types of sets:

We also distinguish between multisets and regular sets. In a multiset, an element can occur multiple times, whereas in a regular set, an element can occur only once. Multisets are also known as "bags".

The distinctions element/value set and multi/regular set are orthogonal. You can have regular element or value sets as well as multisets of elements and multisets of values.

A set is defined with an XML element as follows:

<set name="setname" domain="setdomain" multiset="false|true" 
  <description>Description of the set</description>
  <'set definition' ...>
The attributes in the opening "set" tag are: Like metrics, the sets for one domain must have unique names. Also, within one domain you cannot have a set and a metric of the same name. For example, if you defined a set "Ancestors" for classes, you cannot also define a metric "Ancestors" for classes.

Following the "set" tag is an optional description of the set, enclosed in <description> tags. Set descriptions are currently not shown to the end user, and mostly serve as comments for the maintainer of the metric definition file. See Section 8.6 "Writing Descriptions" how to write (set) descriptions.

Following the description is an XML element that defines the calculation procedure for the set. We describe these calculation procedures in detail in the following subsections.

8.2.1 Projection
8.2.2 Subelements