Working with Code Libraries - Using NxBRE
(Page 3 of 5 )
A business rule generally consists of a condition followed by one or several actions executed if the condition is met.
The following is a classical set of business rules for computing sales discount:
Rule #1
The discount for a customer buying a product is 5.0
percent if the customer is premium and the product is
regular.
Rule #2
The discount for a customer buying a product is 7.5
percent if the customer is premium and the product is
luxury.
Rule #3
A customer is premium if his spending has been min
5000 Euro in the previous year.
We’ll see how these rules translate to a rule base momentarily. A rule base is a file that contains the definitions of several business rules. NxBRE uses these rule bases to control its processing.
Creating rule bases for the Flow Engine NxBRE does not provide any facility for editing rules for the Flow Engine. Since the rules expressed in XML are similar to traditional flow-control programming, using an XML editor such as jEdit (Figure 4-1) that supports schema validation and offers contextual element insertion is generally sufficient.
Fgure 4-1. Using jEdit to create flow-control rules
The example Rule #1 shown previously can be expressed this way:
<Logic>
<If>
<And>
<Equals leftId="CLIENT_RATING" rightId="PREMIUM_RATING" />
<Equals leftId="PRODUCT_TYPE" rightId="REGULAR_TYPE" />
</And>
<Do>
<Integer id="DISCOUNT_PERCENT" value="5" />
</Do>
</If>
</Logic>
The Flow Engine contains an HTML-rendering engine that offers a convenient way to navigate through rules and read them transformed into pseudocode. Figure 4-2 shows one of NxBRE’s unit test rule files transformed in such a manner.

Figure 4-2. HTML pseudocode rendering of flow-control rules
To organize big rule bases, it is a good idea to leverage the notion of a rule set that is supported by the Flow Engine. It allows you to group several rules into a named group that gets evaluated on demand.
Next: Creating rules for the Inference Engine >>
More BrainDump Articles
More By O'Reilly Media
|
This article is excerpted from chapter four of Windows Developer Power Tools, written by James Avery and Jim Holmes (O'Reilly, 2006; ISBN: 0596527543). Check it out today at your favorite bookstore. Buy this book now.
|
|