Reuse using Abstract Rules
Roger
Costello
Click arrow key (
) to navigate to next page
Motivation for Abstract Rules
Suppose you have some assertions that are used by several rules.
Rather than repeating those assertions in each rule, it would be beneficial to place them into an "abstract rule" where they can be reused.
A rule reuses the assertions by extending the abstract rule.
Thus, abstract rules provide a mechanism for reusing assertions.
How to Create an Abstract Rule
Omit the context attribute
Add an attribute "abstract" with a value "true"
Identify the rule using an "id" attribute
This document shows a series of
daily activities
. For each activity we would like to check that the activity finished *after* starting.
Example Abstract Rule
<sch:rule abstract="true" id="start-finish">
<sch:assert test="finish > start">
You must finish after you start
</sch:assert>
</sch:rule>
How to use an Abstract Rule
Create a rule; set the context attribute.
Within the rule nest an <extends> element, with a rule attribute whose value is the identifier of an abstract rule.
Example of using an Abstract Rule
<sch:rule context="eat-breakfast">
<sch:extends rule="start-finish" />
</sch:rule>
View the entire collection of rules:
Daily-Activities.sch
Reuse Plus Extends
In the previous example each rule just used the assertions in the abstract rule.
However, a rule can reuse the assertions in the abstract rule and add additional assertions, e.g.
<sch:rule context="eat-breakfast">
<sch:extends rule="start-finish" />
<sch:assert test="finish < start+15">
Breakfast must not exceed 15 minutes
</sch:assert>
</sch:rule>