Skip to: Site menu | Main content

Drools

Java Rules Engine

Using OR Print

It's ultimately to keep rules independent and more flexible. Shouldn't use OR's just so you can avoid specifying the same consequence multiple times.

ie:

if:

person.getCreditScore() > 800 || person.getFather().equals( Employees.CEO )

then:

loan.setInterestRate( 0.01 );

Here, the logic is intermixed. There's basically 2 business cases here.

1) You've got great credit.

2) You're the CEO's son.

By using/allowing OR, you might model the situation correctly for Right Now, but what if in 6 months, the loan board decides that the CEO's children have to pay 2% instead, while great credit score folks still sit at 1%?

If you'd avoided using OR, then that'd be an easy change to make. If you used OR, now you've got to break the rule apart into 2 rules anyhow.

Rules should express a single business case, really. Using OR to reduce the number of rules simple because they happen to have the same outcome/consequence will make things more difficult down the line, wrt maintaining the rule-set.