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
- element sets, which are sets of UML model elements, for
example, the set of descendent classes of a class,
- value sets, which are sets of metric values.
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.
- name (required): the name of the set, used to
reference the set by other metrics in the metrics definition file.
- domain (required): the type of element for which the
set is defined (e.g., package, class, operation).
- multiset (optional): indicates if this set is a multiset
(multiset="true") or a regular set
(multiset="false"). When omitted, this attribute defaults to
- inheritable (optional): indicates if the set 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 set definition, and the set
can be calculated for all subtypes, too. When omitted or set to "false",
the set definition is not passed on to subtypes.
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.