I am new to drools and am familiar with using the extends keyword to inherit a rule. Question is there a way to inherit multiple rules? This would be similar to using multiple interfaces on a java class. Here's an example of how I would expect it to work but I get an error on rule 3:
rule "rule 1"
when //person name == "John"
then //print "John"
end
rule "rule 2"
when //person last name == "Smith"
then //print "Smith"
end
rule "rule 3" extends "rule 1", "rule 2"
when //person age > 20
then //print John Smith is older than 20
end
Thanks Dawn
I know that this thread is old but it's possible to do the following:
As you can see, you can create a chained rule from super rules inheriting their declared variables.
It isn't well documented yet, but single inheritance does exist in drools. It allows you to create a rule that extends another rule. The sub rule will fire if and only if both of the conditions for the super rule AND the sub rule are true. (See my notes at the bottom).
In the example below, "Flags" is a simple Java class with 2 booleans: isSuperTrue and isSubTrue. The magic phrase is extends "super" as part of the "sub" rule definition. The names of the rules (sub and super) are illustrative and can be changed to any legal rule name.
Note 1: There is an issue in 5.5.0.Final that requires the super rule to be placed before the sub rule in the rule definition file. I've confirmed that the bug is fixed for 5.6.0.CR1.
Note 2: This functionality is indirectly documented in the release notes for 5.5.0.Final in section 4.1.1.3. The core topic is "Conditional named consequences," but it leverages rule inheritance.