[rules-users] Rule architecture question - avoiding condition duplications

Esteban Aliverti esteban.aliverti at gmail.com
Sun Apr 3 08:12:48 EDT 2011


Hi,
Don't worry about performance. Your scenario is perfectly right. Drools will
create a tree (rete tree) with all your Rules. If your Rules have identical
constraints (defined in the same order) the nodes of the tree are going to
be shared among all the Rules. So you will end up with a simple tree.
If you are worring about maintainance, and given the sccenario you
described, maybe the best thing to do is to use inheritance. You can define
a super-rule containing all the common conditions and then crate sub-rules
for each particular situation.
Please read the documentation to learn how rule's inheritance works.

Best regards,
 El abr 3, 2011 4:52 a.m., "Hezi Stern" <hezis at delegatecom.com> escribió:
> Hi all,
>
>
>
> I have a general question regarding best practice or perhaps better put as
> right architecture design.
>
>
>
> We are using Drools (Expert in particularly) to model and execute the
> behavior aspects of our service, which revolves around meeting scheduling
> between various users.
>
>
>
> My main challenge is how to properly structure the rules so that they
> provide the desired flexibility to both modify and control over time.
>
>
>
> Following is a small example which illustrates my question:
>
> I need to determine a specific execution time and it is based on many
> conditions and in general about 15 scenarios where I create a rule per
> scenario. I find that there is a wide set of conditions that are common to
> all scenarios.
>
> So for example a rule would look like:
>
>
>
> when
>
> a1 == X1
>
> a2 == X2
>
> a3 == X3
>
> a4 == X4
>
> b1 == Y1
>
>
>
> Then
>
> Something .
>
>
>
> Another rule would be
>
>
>
> when
>
> a1 == X1
>
> a2 == X2
>
> a3 == X3
>
> a4 == X4
>
> b2 == Y2
>
>
>
> Then
>
> Something else .
>
>
>
> As you can see I am duplicating the a' conditions which are the common
> conditions and the b' is a new unique condition. It seems to me like a
> poorer code maintainability and possibly performance reduction (but I may
be
> wrong, perhaps this is how rules should be written).
>
> I assume this is a common case in rules so my question is what would be
the
> best way (architecturally wise) to implement such cases (e.g. insert a new
> class that indicates that conditions a' are set and base the rules on the
> existence of such a class)
>
>
>
> Thanks
>
> Hezi
>
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110403/b088ef55/attachment.html 


More information about the rules-users mailing list