[rules-users] Rule Reuse Best Practice

Edson Tirelli ed.tirelli at gmail.com
Tue Dec 15 15:08:16 EST 2009


   2 ways:

1. If you have a common superclass/interface for your objects and the
superclass/interface has the method to return your dln, just make use of
inheritance:

when
    MyDTOInterface( dln not matches "^.{5,15}$")
then
   // do something

2. If you want to use composition instead, make dln a top level fact:

when
   DLN( id not matches "^.{5,15}$")
then
   // do something

   Edson

2009/12/15 Jason Davidson <jljdavidson at gmail.com>

> Hello,
>
> What is the best practice for reusing rules?  I've got a license number
> validation rule that I need to reuse for different fact types.  For example,
> the first rule uses the license number in a CitationDTO fact:
> rule "Citation DL Number"
>    ruleflow-group "CitationEntryValidationFlow"
>     when
>         CitationDTO($dln :
> citationSubject.driverLicense.driverAuthorizationId not matches "^.{5,15}$")
>     then
>         resultHolder.setMessage(GenericCitationFieldIds.DLN,"DLN [{0}] must
> be at least 5 characters long and no more than 15 characters long.", new
> Object[]{$dln});
> end
>
> Then I have another rule that uses the license number from the
> InCourtSearchDTO:
> rule "InCourt DL Number"
>     ruleflow-group "InCourtSearchValidationGroup"
>     when
>         InCourtSearchDTO( $d : dln not matches "^.{5,15}$")
>     then
>         resultHolder.setMessage(UserLogonFieldIds.END_DT,"DLN [{0}] must be
> at least 5 characters long and no more than 15 characters long.", new
> Object[]{$d});
> end
>
> Obviously this is a poor implementation because the license number check
> 'not matches "^.{5,15}$"' is duplicated.  Is there a way I can reuse this
> rule?
>
> Thanks!
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>


-- 
 Edson Tirelli
 JBoss Drools Core Development
 JBoss by Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20091215/f5990515/attachment.html 


More information about the rules-users mailing list