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:
- 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.
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"
inheritable="true/false">
<description>Description of the set</description>
<'set definition' ...>
</set>
The attributes in the opening "set" tag are:
- 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
"false".
- 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.
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