[rules-users] Nested Rules

Christine christine at christine.nl
Thu May 22 06:29:37 EDT 2008


On Thu, May 22, 2008 11:30, Vishal Deshmukh wrote:

>   Can i write nested rules like


Sure.


   rule "rule 1 "
   when
       condition is true
   then
       set property in some object

   rule "rule 2 "
   when
       property in some object has been set
   then
       action

However, if you need "nested rules", you probably need to rethink the way
you use rules. It would be easier to write

    rule 1
       if  condition for rule 1 is true
           and condition for rule 2 is true
       then
           action for rule 2.
       end

the way the rule engine works makes this work exactly as you intended: it
checks condition 1, and only if true, it checks condition 2.

As a general design consideration, you want to combine as little
conditions as possible. Suppose you have ten parameters, and you have all
your rules test all paameters. In that case. you're better off hard coding
the procedure.
If you come up with the right set of rules that test only one or two of
the parameters and still produce the desired behavior, then you make
efficient use of the rule engine. I suggest you do some reading on how
rule engines work, it helps you design better rulebases. Don't go into
detail about the Rete algorithm in the Drools documentation, but rather
find some more general guide. I don't know one off the top of my head,
when I find one I'll post it.

dagdag
Christine




More information about the rules-users mailing list