Rules Templates

Powerful templatization mechanism

 

OpenRules Templates provide a powerful while intuitive mechanism for a compact organization of enterprise-level business rules repositories.  Rule templates allow rule designers to write the rules logic once and use it many times. With rule templates you may completely hide rules implementation details from business users.

Simple rule templates.  Rule templates are regular Rules tables such as this "defineGreeting" rules table:

Rules void defineGreeting(int hour, Response response) - Signature with parameters
C1 C2 A1 - Conditions and Actions identifiers
min <= hour hour <= max response.map.put("greeting",greeting);  - Java snippets describe condition/action semantics
int min int max String greeting - Parameter types and names
Hour From Hour To Set Greeting - Business names for conditions and actions

We may use this decision table as a template to define different greeting rules for summer and winter time. Simple templates do not usually contain any rules because concrete template implementations (actual rules tables) will provide the rules. The actual rules table implements the template with particular rules:

Rules summerGreeting template defineGreeting
Hour From Hour To Set Greeting
0 10 Good Morning
11 18 Good Afternoon
19 22 Good Evening
23 24 Good Night

and

Rules winterGreeting template defineGreeting
Hour From Hour To Set Greeting
0 11 Good Morning
12 17 Good Afternoon
18 22 Good Evening
23 24 Good Night

Note that Rules tables "summerGreeting" and "winterGreeting" do not have technical information at all - Java snippets and a signature are defined only once and reside in the template-table "defineGreeting".  We will refer to these rule tables created based on a template as "template implementations".  Along with the keyword "template" you may use keywords "extends" or "implements".

Simple templates require that the extended tables should have exactly the same condition and action columns.

OpenRules supports several rule templatization mechanisms:

  • Simple templates: rule tables inherit the exact structure of templates that they extend

  • Templates with defaults rules for multi-hit rule tables

  • Templates with defaults rules for single-hit rule tables

  • Partial template implementation

  • Templates with optional conditions and actions.

You may create templates for both vertical and horizontal rule tables.

Default rules inside templates.  The release 5.1 adds an ability to define some rules directly in a template that will be executed when all other rules inside template implementations fail. For example, consider this template for multi-hit rule tables:

Rules void defineGreeting(int hour, Response response)
C1 C2 A1
min <= hour hour <= max response.map.put("greeting", greeting); 
int min int max String greeting
Hour From Hour To Set Greeting
    Invalid Greeting

The following implementation of this template

Rules summerGreeting template defineGreeting
Hour From Hour To Set Greeting
0 10 Good Morning
12 18 Good Afternoon
19 22 Good Evening
23 24 Good Night

by mistake misses the hour 11.  So, if these rules are launched between 10 and 12 the default rule from the template will not be overridden by any rule from the implementation and the "Invalid Greeting" will be produced.

Let's consider a template for single-hit rule tables like such as this one:

Rules String defineSalutation(Customer customer, Response response)
C1 C2 C3 A1
customer.gender.equals(gender) customer.maritalStatus.equals(status) customer.age < min response.map.put("salutation",salutation);
return salutation;
String gender String status int min String salutation
Gender Marital Status Age is Less than Set Salutation
      InvalidSalutation

The default rules from the template will be executed only when all rules from an implementation table failed. 

The defaults rules allows a rule repository designer to define unified rules for exceptional conditions only once in the templates instead of repeating them many times in multiple template implementations.

Partial template implementation. With the release 5.1 you may create large rule templates but use not all but only selected conditions and actions in the rule tables created based on these templates.  To do that, it is enough to add the second row that specifies the names of the selected conditions and actions like in the example below:

Rules defineSalutationBasic template defineSalutation
C1 C2 A1
Gender Marital Status Set Salutation
Male   Mr.
Female Married Mrs.
Female Single Ms.

Here the column C3 from the template "defineSalutation" above is ignored.

Optional conditions and actions.  If the majority of the template implementations do not use a certain condition/action from the template, then this condition/action may be explicitly marked as "optional" by putting the condition name in the brackets, e.g. "[C3]" or "[Action2]".  In this case it is not necessary to use the second row to specify the selected conditions in the majority of the rule tables. Only template implementations that actually need optional columns will use the second row to explicitly specify the optional columns.

The standard sample project "HelloJavaTemplates" demonstrates the use of different templatization features - see files HelloTemplates.xls and HelloRules.xls

Click here to learn more about Rule Templates.

Benefits.  While the new rules templatization (or rules inheritance) mechanism is simple and intuitive it brings enormous advantages from the rules management perspective: 

  • Write once use many times 

    • Write rules for one state or country and then use them as a template for all other states/countries

    • Changes in the implementation of a rule template are automatically propagated to all rule tables that extend this template.

  • Complete separation of business and technical views 

    • Business people have less to learn and do not have to even know about the implementation details

    • Technical people have more freedom in rule templates design and maintenance not being afraid to scare business counterparts by complexity of rules signature and implementation logic. Templates usually placed in a separate subdirectories inside a rule repository

    • By placing rule templates and rule tables in separate files you may essentially simplify authorization control and who-does-what assignments

  • Rules repository becomes smaller and easy to maintain

    • Templates allow to avoid a "paste-copy" approach by minimizing the total amount of code and size of rule tables

    • While preserving the same structure changes in the templates and rules could be done independently

  • Expedited initialization of OpenRulesEngine

    • Use of rule templates essentially minimizes the initialization time when OpenRulesEngine downloads all rules for the first time

    • Based on the size and design of the existing rules repositories the gain in the initialization time could vary from 2 to 5 times
       

  • Libraries of rule templates specific for different lines of business

    • Rule templates provides an ability for creation of OpenRules template libraries for different lines of business.  It allows leading organizations in different industries to implement already established business standards such as ACORD for insurances or MISMO for mortgages as a set of rule templates. Even if the library implementers prefers to use their own business models initially they always may change template implementation later on without changing the business rules themselves

    • A similar model works well for software vendors who define and maintain their product specific template libraries in accordance with their latest business object models.

 

 

 

Welcome
Welcome
Business Rules Repository Decisions Top-Down Semantics In Concert Business Analyst Decisioning
Welcome
themed object
Business Rules - Time to Excel
Bookmark and Share