Contents > 9 Extending the Metrics and Rule Engine > 9.1 Metric Procedures > 9.1.1 Conception of a New Metric Procedure
9.1.1 Conception of a New Metric Procedure
Assume we wish to calculate a "lack of cohesion" style metric similar to LCOM
proposed by Chidamber and Kemerer in [CK94]. These metrics count pairs of elements
that have or have not something in common, for instance, the number of pairs of methods in a
class that use no common attributes, or, with regards to applicability to UML
designs, the number of pairs of operations of a class that do not
have at least one parameter type in common. In the latter case, just obtaining
the set of parameter types of an operation is easy enough:
<set name="ParaTypeSet" domain="operation">
<description>The set of parameter types of an operation.</description>
<projection relation="context" target="parameter" element="parametertype" />
</set>
What we would need then is a metric that takes each pair of operations of a class,
and counts those pairs that have a parameter type in common. None of the
existing metric procedures in SDMetrics accomplish this, but if we had such a
procedure, the definition of the metric could look something like this:
<metric name="LCOM_Parametertypes" domain="class">
<description>Lack of cohesion in operations based on operation
parameter types.</description>
<pairwise relation="context" target="operation"
paircondition="size(_first.ParaTypeSet * _second.ParaTypeSet)=0" />
</metric>
The idea is that the metric obtains the set of operations of a class (as we would
in a standard projection), and then evaluate the "paircondition" expression for each
operation pair. The variables "_first" and "_second" in the pair condition refer to
the first and second operation of the pair. The given expression evaluates to true if
the intersection of the parameter types of the operations at hand is empty.
To make the procedure more flexible, we could have it support a few more attributes:
- Users should be able to specify the set to operate on as they are used to from
the "projection" procedure (Section 8.1.1 "Projection"), using either the "relation" or "relset"
attribute, and the standard filter attributes "target", "element", etc.
- The procedure should provide an option to not only yield pairs of elements
of a set, but tuples. For pairs, only one combination of elements A and B
will be reported as either {A,B} or {B,A}, the order of elements
carrying no semantics. For tuples, both combinations
(A,B) and (B,A) will be reported, distinguishing the order of elements.
We therefore define an optional attribute "tuples" that takes values "true" or "false" to
indicate if we want to access pairs (value "false", also the default) or tuples (value "true").
- The procedure should optionally report the combination of an element with itself.
We therefore define an optional attribute "withself" that takes values "true" or "false".
When set to "true",
the procedure additionally reports one combination {A,A} for each model element.
- In addition to just counting the number of pairs/tuples that satisfy the pair condition,
the procedure should support the "sum" and "stat" attributes as we know them from the
"projection" and "subelements" procedure (see Section 8.1.1.7 "Attributes "sum" and "stat"").
When "sum" is set, the specified expression
will be evaluated for each reported pair, and the metric will report the sum of all values
(or the maximum/minimum value when attribute "stat" is set accordingly).
- The "paircondition" attribute should be optional. If not set, all reported combinations
will be processed.
Prev |
Up |
Next |
Section 9.1 "Metric Procedures" | Contents | Section 9.1.2 "Implementation of the Metric Procedure" |