![]() |
![]() |
Examples |
|
|
|
|
|
Learn By Examples |
|
|
|
|
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:
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:
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:
Note two important points:
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:
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.
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Copyright © 2003-2008 OpenRules, Inc. All rights reserved | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||