<div><br></div>   Zack,<div><br></div><div>   The use of rule names as part of your logic (LHS) is a bad practice (as you noticed already) for many reasons. I discussed this yesterday during my presentation at the Rules Fest... I will make the presentation available later this week.</div>
<div><br></div><div>   I think the problem is that you are mixing data driven constraints with rule explicit constraints. There are several ways of improving your rules depending on your goals. For instance, if your AlertThreshold is supposed to constrain your instance, then it should &quot;know&quot; which attribute should be tested. Using a strategy pattern (or simply method overload if you prefer), you could have the method testing your instance directly:</div>
<div><br></div><div>       $entity : TestedEntity( )<br>       AlertThreshold( entity == $entity, isOverThreshold( $entity ) )  <br></div><div><br></div><div>   Another way is to have an ENUM for the type of threshold you are dealing with. This will avoid arbitrarily creating dependencies between facts and rules.</div>
<div><br></div><div><div>       $entity : TestedEntity( )<br>       AlertThreshold( entity == $entity, type == ThresholdType.TEMPERATURE, maxThreshold &lt; $entity.temp )   <br></div><div><br></div><div>   My .02c. Hope it helps,</div>
<div><br></div><div>    Edson</div><div><br></div><br><div class="gmail_quote">2011/10/25 zstlaw <span dir="ltr">&lt;<a href="mailto:zstlawre@akamai.com">zstlawre@akamai.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Each item I am testing MAY have overridden the default thresholds or disable<br>
the rule entirely.  I would prefer to have this data related to the item I<br>
am testing rather than have each rule manage customized behavior for<br>
thousands of different types of objects.<br>
<br>
The object could have a map of rule thresholds it overrides, but for<br>
simplicity I assume there is a method to return the current threshold for<br>
the current object.  is there a better way to perform this kind of logic?<br>
Example of my current code:<br>
<br>
declare TestedEntity<br>
    temp : Double<br>
end<br>
<br>
declare AlertThreshold<br>
    maxAllowed : Double<br>
end<br>
<br>
rule &quot;Check temperature&quot;<br>
    when<br>
        $entity : TestedEntity( )<br>
        // would prefer to use drools.getRule().getName() on next line<br>
        AlertThreshold($entity.temp &gt; maxAllowed)  from<br>
$entity.getAlertThresholdForRule(&quot;Check temperature&quot;)<br>
    then<br>
        // raise alert<br>
end<br>
<br>
I dislike hard-coding the rule name as it leads to copy paste errors.  I<br>
can&#39;t insert thresholds easily unless I define different ones for each rule<br>
and I want to be able to fall back to defaults easily.  This is a type of<br>
problem I have come up against several times now so I feel like others must<br>
have dealt with it before.  The idea of writing copies of rules tailored to<br>
each Entity appeals less than a generalized way of doing this.  By doing<br>
this I want to contain complexity.  Dozens of slightly different<br>
implementations of the same rule would be much harder to test and support.<br>
I am dealing with hundreds of thousands of facts today and will need to<br>
scale to millions before I can deploy fully.  But with that large number I<br>
need to have ways to manage exceptions to the general case just to keep<br>
complexity manageable.<br>
<br>
Thanks,<br>
Zack<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Advice-on-varying-rule-behavior-based-on-object-tested-tp3452814p3452814.html" target="_blank">http://drools.46999.n3.nabble.com/Advice-on-varying-rule-behavior-based-on-object-tested-tp3452814p3452814.html</a><br>

Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br><br clear="all"><div><br></div>-- <br>  Edson Tirelli<br>  JBoss Drools Core Development<br>  JBoss by Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>
</div>