Business Rules: Decision services for Business Applications


Experience in the use of BRS shows that little regard was paid to the encapsulation of business logic in the architecture of applications in use today, irrespective of whether these are host systems or server based systems. Business rules are for the most part closely interwoven with the technical parts of the program. 

Seemingly minor modifications to business logic often precipitate significant program modifications. Exacerbating the problem is that if program documentation is available at all it is useless for understanding the business logic implemented due to the mixture of functional and technical aspects. 

But, various flexible yet powerful technologies through out different languages make these things easier to design and code. 

Business Rules Systems solve this problem. With these business logic is structured and encapsulated in the application to make it easy to change. 

I am blindly pointing to the BRMS (Business Rules Management System) concepts, a hot thing in today's technology world. A lot of applications are designed to have these as their base of their application decision making process.

Some of them are, 
  1. Microsoft Work Flow Engine 
  2. BizTalk
  3. JAVA : Web logic
If you deeply look into WF and BizTalk applications, there must be something in the base to take a decision and based on the decision, the application takes the next step.

E.g. in WF you need to call purchase web service, if the total quantity is less than a defined benchmark. 

So if we code this in .NET, 

if (BalloonStore.TotalQuantity < 50) 
{
    (BalloonStore.CallWebservice == True)
}

So there is process engine, to check the value in "CallWebService", if it is true, then it starts the process of calling the web service and do the further processing.

In a normal and conventional way, we code these checking in the part of the process engine. 

Now, the management decides, that "should be checked the color of the balloon" along with the quantity.

Again, normally, we open up the class or library and change the condition and compile, deploy etc...finally start working

And, definitely, without doubt, these are the nightmare to anybody who supports the application, code and the client 

(I know, people will get irritated and curse the management for changing the rules often or the people who made such architecture of the application!!!!!!!!!!!!!).
And, big players like JAVA, Microsoft are just giving more importance to this, and they already changed the way we do the coding.

It is very much visible and practicable: If you ever worked with Work Flow, WPF or BizTalk etc. (Find out more about, run time loading rules, XAML, BizTalk Rule Engine, Work Flow Rule Engine)

SO, I VERY MUCH CONVINCED THAT, THIS IS THE WAY TO CODE AND MAKE FASTER AND FLEXIBLE

I was searching for a Business Rule Engine, which can be integrated to our application and providing an interface to change the rules in text/XML editor.

I cornered an application in JAVA; DROOLS and DROOLS.NET by Apache, a BRMS system, is matching our requirements. It is having a library and a simple way of coding your rules. 

You use these libraries in .NET and JAVA and code it as you required. The rule files can be changed in runtime and no changed in your code is required. 

package TestRules
import RulesData

rule "R1Domestic"
when
inputData : InputData (TravelType == "Domestic")
then
inputData.ServiceCharge =175;
inputData.Discount =0;
end

This is a sample file of DROOLS .NET, Let me explain this,
 
If the TravelType is Domestic (Travel related), then the following service changes, discounts applicable.

The processor will parse the rule file and execute it. The result will be you get back the InputData object, with updated values. 

Now, your actual business application can take next action, depending on the results you got.

It almost solves our problem, and we created some complex rules using this and working fine. 

But, we some of the functionalities are not available in (.NET Version) here list
  1. Iterate through collections with small statement in the rule file (no code changes) 
  2. Checking against the collections or master data (CargoTypeMaster contains cargoType or CargoTypeMaster contains "FP") 
  3. Check the data with multiple class as in c# 

    (PersonDetails.FirstName == "ABC")
  4. Update the data and use them in the next rule (If the second rule need to use the updated data of first rule) 
  5. No changes required in the in case of Class change, structure change, type change. 
  6. Else part in the rules 
These are some points, which I think will make huge difference and give complete flexibility of decision making. 

I was sure that, we can do it; the problem is, the actual source code of DROOLS is in JAVA and they are updating the JAVA version of the rules engine with enhancements not the .NET version.

So, I should be thinking out of box, and find out the rule engine used by WF and BizTalk is doing the same thing. One advantage will be it is in the same technology.

But, WF and BizTalk rule engines are using XAML format, to store the rules instead of a text file in case of Drools.

Believe me, it seems to be hard way to understand the format and write some thing like this. So, I stick with the text file for rule defining and use the .NET rule engine to parse them. 

The only think I need to do is, parse the text file and convert into a rule in run time and execute it and created a new rule format in text file (definitely inspired from JAVA Drools). 

So...simple..............

rule "R1_Sample11"
when
Fare in FareData
Fare.GrossFare > 1500&Fare.GrossFare < 3500
and Airline contains("BA")
and DeparetureMonth == 12

then
Fare.AlertType = "EMAIL"
Fare.ShowAlert = True
else
Fare.AlertType = "None"
Fare.ShowAlert = False
end

This is a sample file of new Rule Engine, Let me explain this,

1. Fare in FareData : The FareData is a collection and which contains Fare object
2. So, the next line after wards are doing a check in Fare object by iterating all the objects in the collection

Simply, 

"Check the GrossFare in Fare object and Airline (collection) contains "BA" and DepartureMonth is December.
Update the AlertType and ShowAlert property"
And repeat this check for each fare object in the FareData collection"

You can write any number of rules in a file.

How is this? Think how many lines of code you are going to write to do this...and if tomorrow another check is added...then........

 
Believe me; it really made my life of architecture design much flexible and dynamic...

Never thought, that the dynamism of the coding will go this high...


Similar Articles