问题
I have a .drl file which contains more than 100 rules. There are approximately 40 rules like rule "1", some 35 like rule "2" and rest are like rule "3".
rule "1"
when
m: MyBeanClass( something1 == "train" && something2 == somevalue2)
then
m.setSomeThing(someOtherValue);
update(m);
end
rule "2"
when
m: MyBeanClass( something1 == "bus" && something2 == somevalue2)
then
m.setSomeThing(someOtherValue);
update(m);
end
rule "3"
when
m: MyBeanClass( something1 == "car" && something2 == somevalue2)
then
m.setSomeThing(someOtherValue);
update(m);
end
On firing all rules, all the rules will get executed, which I do not want. If "something1" is not equal to "train", then I want the execution flow to directly go to the 41st rule which is like the rule "2" here.
Please suggest.
Thanks, Shardul
回答1:
I'd have three scoping rules for "car", "bus", and "train" to set a value, then 41 rule took in that scoped value and operated on it.
You still have to write 44 rules, but you don't have to repeat the 41 for each scoping case.
来源:https://stackoverflow.com/questions/17260675/nested-rules-in-drools