Then there is the possibility of extending a rule, which lets you inherit the conditions of one rule to any number of other rules:
rule "multiple account owners"
when
$acc: Account( owners.size() > 1 )
then end
rule "multiple and open and valid"
extends "multiple account owners"
when
Account( this == $acc, open && valid )
then
If you follow Andy's idea, consider using insertLogical and a reference to the Account in question (unless you're investigating one Account fact at a time):
rule "multiple account owners"
when
$acc: Account( owners.size() > 1 )
then
insertLogical( new Multiple( $acc ) );
end
Be careful with this approach so as not to have rules fire prematurely with the negated (!) form of the property represented by the auxiliary fact, e.g.,
rule "funny account"
when
$acc : Account( balance > 10000000 ) # can have more than one owner
not Multiple( account == $acc )
then ... end
This can fire before "multiple account owners" asserts Multiple, unless that rule is given a higher salience. Also, be aware of the effect of evaluating all of these properties by inserting auxiliary facts: this overhead is created anyway, even if a certain Account will not need them all in order to be processed.
Finally, there's the idea of an Adapter (or wrapper) for Account providing any number of fancy getters for Account:
rule "wrap account"
when $acc: Account() not Wrapper( account == $acc )
then insert( new Wrapper( $acc ) end
rule "multiple valid-open"
when Wrapper( multiple && validOpen )
then ... end
And you may, of course, resort to DRL functions:
function boolean multiOwners( Account account ){
return account.getOwners().size() > 1;
}
rule "multi valid open"
when $acc: Account( eval( multiOwners($acc) && openValied($acc) ) )
then ... end
(I'm not sure whether you need the eval in the latest Drools version(s).)