<p>We use dedicated Java classes named after the kind of constant they represent, like Slack in your case or RetirementAge, LegalAgeThreshold. Most of the time, they contain a single property &quot;value&quot;.</p>
<p>This makes it easy to use Drools patterns to match them, plus we get rather strong type checking during rules compilation AKA packaging. We only need around a dozen constants in our rules and their values rarely change (like once every few months). The amount and type of constants are even more static: add/remove one constant per year on average.</p>

<p>Best regards</p>
<p>Ansgar</p>
<div class="gmail_quote">Am 18.02.2013 20:52 schrieb &quot;Willem van Asperen&quot; &lt;<a href="mailto:willem@van.asperen.org">willem@van.asperen.org</a>&gt;:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

  

    
  
  <div bgcolor="#FFFFFF" text="#000000">
    Hi All,<br>
    <br>
    I have a bunch of rules that evaluate using some constant variable
    (say &quot;slackTicks&quot;). Currently, in my rules, I write down the value
    of this &quot;slack&quot; each and every time I use it, for example:<br>
    <br>
    <code>TransferSchedule( tick &gt; currentTick - 10d )</code><br>
    <br>
    where 10 is the slack.<br>
    <br>
    A solution would be to insert constant facts:<br>
    <br>
    <code>Constant( key = &quot;slack&quot;, $slackTicks : value )</code><code><br>
    </code><code>TransferSchedule( tick &gt; currentTick - $slackTicks )</code><br>
    <br>
    Or inject a global properties object:<br>
    <br>
    <code>global Properties constants</code><code><br>
    </code><code><br>
    </code><code>$slackTicks :
      Double.valueOf(constants.getPropertyValue(&quot;model.slack&quot;, &quot;0&quot;))</code><br>
    <br>
    Or, the last one I can think of: a public final static on the fact
    class:<br>
    <br>
    <code>TransferSchedule( tick &gt; currentTick -
      TransferSchedule.SLACK_TICKS )</code><code><br>
    </code><br>
    These all cross the boundary between Java and Drools. In my Java
    code I have to insert the Constant facts or inject the global. When
    my drools developers think of some new ways to create the rules, I
    run the risk of having to go in and modify the .properties file or,
    worse, change the Java code.<br>
    <br>
    To be able to define a &quot;constant&quot; would be a clean solution:<br>
    <br>
    <code>declare</code><code> constant double SLACK_TICKS = 10</code><code>;<br>
    </code><code>
    </code><code><br>
      ...<br>
    </code><code>
      TransferSchedule( tick &gt; currentTick - SLACK_TICKS )</code><code><br>
      ...<br>
    </code><br>
    This separates the rules from the Java code and give the rules
    developer all freedom to do whatever they want to make constant.<br>
    <br>
    Ah, just thought of another way to do it. You can insert the facts
    from within Drools itself:<br>
    <br>
    <code>declare Constant</code><code><br>
    </code><code>    key : String</code><code><br>
    </code><code>    value : Object</code><code><br>
    </code><code>end</code><code><br>
    </code><code><br>
    </code><code>rule initialize</code><code><br>
    </code><code>    salience 100000</code><code><br>
    </code><code>    when</code><code><br>
    </code><code>        // always</code><code><br>
    </code><code>    then</code><code><br>
    </code><code>        insert( new Constant( &quot;slack&quot;, 10d ) );</code><code><br>
    </code><code>        //... other constants go here</code><code><br>
    </code><code>end</code><code><br>
    </code><br>
    I will still have to &quot;capture&quot; the constants that I need in every
    rule with a Constants( key == &quot;...&quot;, $c : value ) premise, though...
    And you would need to add some more Constant classes to cater to
    contain type safety...<br>
    <br>
    What&#39;s your thought? What strategy do you use?<br>
    <br>
    Regards,<br>
    Willem<br>
  </div>

<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></blockquote></div>