As we've discussed earlier, we should strive to keep our rules simple. To do so, sometimes, we break down a rule into multiple rules, making insertions of new data in the engine to trigger other simple rules. This helps in keeping the rules manageable as simpler rules will be easily understood. Here's a small example of how we can do such a thing:
rule "determine large orders" when $o: Order(total > 150) then insert(new IsLargeOrder($o)); end
In this way, we won't have to define what we consider a large order more than once. If we want to change this consideration in the future to, let's say, a total larger than 200, we will only have to change it once.
The one consideration that we need to have with this approach is that if the condition that triggered the insertion of IsLargeOrder
might stop being true in the future. If some rule or a piece of code changes the order to have a smaller total, the IsLargeOrder
object would still be in the working memory...