Examples
Home Product Company Contact 
 Learn By Examples


Home
News
Overview
Examples
Methodology
Components
Rule Repository
Rule Templates*
Architectures
Downloads
Documentation
Step-By-Step*
Support
Add-Ons
Fun Lab*
Jump-Start
Inside Track
Events
What People Say

 

 

   


Here are several examples of business rules that can help you to quickly understand how OpenRules represents business rules. Follow the links below to see different spreadsheets with business rules:

bullet HelloRules.xls - rules that define customer greetings based on the time of day and customer's attributes
bullet Vacation.xls - rules that calculate vacations days
bullet UpSell.xls - simple customer profiling and up-selling rules
bullet Loan.xls - loan pre-qualification rules with web forms
bullet HealthCareRules.xls and HealthCareForms.xls - rules and forms for clinical guidelines. To learn OpenRules through examples, we recommend you to look at the case study "Clinical Guidelines".


What you see are actually working business rules and forms represented in Excel. Using a familiar Excel interface, a business user can enter new rules or change the existing ones without focusing on implementation details. However, the same spreadsheets include hidden cells where technical people put pieces of their Java code to express rules semantics. Expand the spreadsheets one level deeper (just click the "+" button) to see the rule implementation details. Actually, each spreadsheet has two views presented by the buttons [1][2] at the top left corner:

  [1] - Business view
  [2] - Technical view.

 

Below is a brief description of the "HelloCustomer" example, in which we want to define simple rules that will allow us to generate the correct greeting for a customer.  For example, if a customer Robinson is a married female who calls our auto-answering service at 12:30 PM, we want to response with "Good Afternoon, Mrs. Robinson!"  Here are the corresponding rules tables in Excel:

 

You can change your understanding of morning hours by simply adjusting Hour From and Hour To values.  This decision table is intuitive and oriented toward a business user.  However, its title along with the table name "defineGreeting" already includes some technical information:

bulletparameter "hour" that supposed to contain the current time of day
bulletparameter "response", through which the table should return an appropriate greeting

While we can always hide this information from a business user, it is an important specification (so called "signature") which tells an external program or other rules how to call these rules.

Here is another example of simple business rules that specify how to salute a customer based on his/her gender and marital status:

You can add one more column "Age" here to be more accurate differentiating between "Ms" and "Mrs".

Again, these views of business rules are oriented toward a business user. Where is the underlying logic? You have to be a technical person to write it: not a programming guru but basic knowledge of the "C" family languages like Java would be useful. These Excel spreadsheets include password protected additional rows that you can see if you just press the button "+" in your Excel examples.  Here is the extended view of the first table:

As you can see in the attached comment, this rule table has two conditions (columns "C1" and "C2") and one action "A1". The first row specifies the semantics, for example the expression "min <= hour" explains what "Hour From" stands for. It tells that the condition C1 is true if the current "hour" is greater or equal to the minimum "min" specified in this column. The expression "hour <= max" in the column C2 says that the current hour should be less or equal to the maximum hour. The A1 action semantics is slightly more difficult piece of Java code. It relies on your knowledge of the proper Java object "response". When both C1 and C2 are satisfied we want to assign a proper String "greeting" into the response. In this example, it is done via a hash map defined inside class Response.

The same table may be represented with only one condition column that checks if the parameter "hour" belongs to a certain time interval:

Rules void defineGreeting(int hour, Response response)
C1 A1
interval.contains(hour) response.map.put("greeting", greeting); 
FromToInt interval String greeting
IF
Hour belongs to interval
THEN
Set Greeting
[0;11] Good Morning
[12;17] Good Afternoon
[18;22] Good Evening
[23;24) Good Night

Instead of an interval [12;17] you may write any reasonable natural language expression such as "from 12 to 17", "12-17", "greater than or equals to 12 and less or equals 17", etc.

You may completely hide implementation details by using Rule Templates. For example, the above table for summer greetings may look like:

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

Note two important points:

  1. OpenRules actually "married" Microsoft Excel with Java
  2. In the same document OpenRules clearly separated rules logic supported by technical and non-technical people.

Both Business and Technical people would appreciate the power of this Excel-Java combination.

For technical people, here is one more Excel table that defines the logic of launching both "defineGreeting" and "defineSalutation" rule tables:

We also want to point out that you are not limited to Java only. With OpenRules, along with Java you can run the same rules with external data types defined in XML or in Excel. OpenRules uses different data types without generation of intermediate Java classes.  The proper rule projects HelloJava and HelloXML are included into the standard OpenRules installation.

Sometimes instead of creating a decision table it is more convenient to represent rules using simple Java expressions. For example, instead of a decision table with just 2 rows, we may create a simple Method table:

Method void ValidateIncomeRules(LoanRequest loan, Customer customer)
if ( customer.monthlyIncome * 0.8 - customer.monthlyDebt > loan.amount/loan.term )
     loan.incomeValidationResult = "SUFFICIENT";
else
     loan.incomeValidationResult = "UNSUFFICIENT";

You may read more about OpenRules tables at the User Guide OpenRules installation includes many examples designed to illustrate development and application techniques useful when developing rules-based applications.  Looking at the examples is a good way to become familiar with the process of application development in OpenRules environment.  You can use these sample applications as a basis for your own application or as a reference when coding new applications.  You can also use these as a learning tool.  Each sample has a readme file that will describe how to do the base setup for the application and will explain how to build and run the application.  A complete list of sample applications can be found here.  The document Getting Started provides general guidelines how to install and work with OpenRules sample projects.

Finally, with OpenRules you can use Excel to create dynamic rules-based Web interfaces. Here is an example of a simple Web-based interface to test our greeting rules:

Changing the age, gender and/or marital status and pushing the button "Update Greeting" one can test all combinations for the previously defined business rules. This web page was automatically generated using just one Excel table:

To learn more, please download these and other examples from here, change the rules, and run them from the provided batch-files or from your own Java code.  See how complex projects with extensive rules and web components can be organized and maintained under Eclipse with OpenRules plug-ins.

Contact us at OpenRules, Inc. with your questions, suggestions or if you need support or consulting services.

 




Back Next
Copyright © 2003-2008 OpenRules, Inc. All rights reserved