One last important aspect of rule creation is the possibility of having a rule hierarchy. Just like classes, rules allow inheritance between them. If rule B
inherits rule A
, it will be the same as having all the conditions in rule A
at the beginning of the conditions of rule B
. The following table shows two rules using inheritance and their equivalent without it:
rule "A" when s: String(this == "A") then System.out.println(s); end rule "B" extends "A" when i: Integer(intValue > 2) then System.out.println(i); end
|
rule "A" when s: String(this == "A") then System.out.println(s); end rule "B" when s: String(this == "A") i: Integer(intValue > 2) then System.out.println(i); end
|
This can be a good strategy to manage rules that have repetitive conditions but still change structure. However, you need to be careful when deciding to use rule inheritance. Inheriting from another rule means that your sub-classed
rule will not be independent; people reading...