Single inheritance in Drools for rules isn’t very well documented; however, it is possible to create a rule that extends another rule in Drools.
NOTE: This example is known to work for Drools 5.3.0.Final and subsequent releases, and may work in prior 5.X releases. This example was built using Drools 5.5.0.Final; and was tested in Drools 5.3.0.Final.
The following example shows a simple case of Drools single inheritance for a rule. The ‘Object’ is a Java class that has two defined boolean fields, condition1 and condition2. The parent rule “Base” is defined first, and the child rule “ExtensionOfBase” is defined after the rule “Base”. The keywords extends is used to identify the extension of the parent rule “Base” within the child rule “ExtensionOfBase”.
NOTE: The child rule will fire if, and only if, the conditions for the parent rule and child rule are evaluated as true. Also, if the child rule “ExtensionOfBase” is evaluated as true, both the parent rule “Base” and child rule “ExtensionOfBase” semantic blocks are executed.
rule "Base" when Object ( condition1 == true ) then System.out.println("Base will fire if Object.condition1 evaluates to true"); end rule "ExtensionOfBase" extends "Base" when Object ( condition2 == true ) then System.out.println("Base will fire if Object.condition1 and Object.condition2 evaluates to true"); end