Contents > 8 Defining Custom Design Metrics and Rules > 8.3 Definition of Design Rules > 8.3.1 Violation

8.3.1 Violation

The "violation" procedure defines a condition expression for a model element. If the condition evaluates to true, the model element violates the rule and is reported.

For example, consider a rule stating that an abstract class should have child classes. The abstract class itself cannot be instantiated, so child classes are required for the class to become useful in the system. That rule can be defined as follows:

<rule name="NoSpec" domain="class" category="Completeness" severity="2-med">
  <description>Abstract class has no child classes, must be 
               specialized to be useful.</description>
  <violation condition="abstract='true' and NOC=0" />
</rule>
The condition expression condition checks if the class is abstract, and the number of children of the class (metric NOC) is zero.

The "violation" procedure has two attributes;