First approach is more like a quick-n-dirty trick.
It only works if you are sure that only one RuleContext exists in the working memory.
If not ... the rule will lead to really strange results ...
The real question is why you have rules like that, what was the initial justification? To
me it seems to be a mistake, written by someone that did not understand well inferences
systems, who has fixed his bugs by restricting to one single RuleContext object... or may
be not even ask hilmself the question if this was a initial constraint to have one single
object.
The second approach is the correct one because :
- You want to test one single objet --> You write one single pattern. Using two
patterns means (in common sens of everybody writing rules) matching two objects ...
- If you give more than one RuleContext, it will still work
Does it matter? Not sure that it will change perfs for one single object in WM, but it is
the correct way to do, so yes (to me).
At least, add a test in all you first rule's pattern to test a common identifier or
the object's reference (to ensure that this is the same object), but it will remain a
trick (safer, but still not clear) ....
----- Mail original -----
De: "larryc" <larry.chambers(a)sentry.com>
À: rules-users(a)lists.jboss.org
Envoyé: Mercredi 18 Avril 2012 18:15:09
Objet: [rules-users] Best way to write a rule where pattern has multiple constraints
I was reviewing some of our DRLs and noticed some rules written like this:
when
RuleContext(billingSystem == "ABC")
RuleContext(policyStatus == "active")
RuleContext(renewalDueDate != null)
then ...
while others were written this way:
when
RuleContext(billingSystem == "ABC", policyStatus == "active",
renewalDueDate != null)
then ...
There should only be one RuleContext fact in the knowledge base at one time.
Which approach is better? Is one approach more efficient for Drools than
the other? Does it matter?
Thanks!
--
View this message in context:
http://drools.46999.n3.nabble.com/Best-way-to-write-a-rule-where-pattern-...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users