Contents > 8 Defining Custom Design Metrics and Rules > 8.5 Expression Terms > 8.5.1 Constants and Identifiers > 8.5.1.2 Identifiers

8.5.1.2 Identifiers

Identifiers denote the name of attributes of metamodel elements, the name of metrics, the name of sets, or variables (which we will discuss in more depth in a moment).

An identifier is a letter or underscore (a-z, A-Z, _), followed by any sequence of digits (0-9), letters, and underscores. Examples of valid identifiers are: i, visibility, NumOps, set2, Metric1_a, _principal.

By convention, attribute names start with a lowercase letter, metric and set names with an uppercase letter, and variables with an underscore. This avoids name conflicts between metrics or sets, attributes, and variables.

Variables

Metric, set, and rule procedures can define variables that hold values with special meanings for the calculation. We access those values in metric, set, and condition expressions. SDMetrics defines two standard variables _self and _principal.

The variable _self yields the model element for which the expression is evaluated. The variable _principal yields the model element for which the current metric, set, or rule is evaluated. Variables _principal and _self need not be the same element. In fact, the variable _principal should only be used if it is not the same element as _self.

Consider the following example. The metric counts, for a class A the supplier classes on which A depends that have more operations than A:

<metric name="SuppliersWithMoreOperations" domain="class"> 
  <description>The number of classes this class depends on that have
     more operations.</description>
  <projection relation="depclient" target="dependency" element="depsupplier" 
    eltype="class" condition="_self.NumOps > _principal.NumOps"/>
</metric>
The condition expression is evaluated, in turn, for each supplier class of class A. The variable _self therefore refers to the supplier class. The variable _principal always refers to class A for which the metric is calculated.

Note: the condition expression in the above example could have also been written as "NumOps > _principal.NumOps", because the identifier NumOps will be interpreted as a metric of the model element for which the expression is calculated. In fact, variable _self is rarely needed in practice. Useful applications include