In a previous post I showed how Velocity templates can be used to perform data transformations (Mappings). This time I will take the same sample to show how to use Drools to address the same problem.
I have written for that purpose a tutorial on Drools covering local environment configuration and debugging.
Drools project started as a Rules Engine but nowadays it includes way more than that. I am showing here just how to use Drools for a Rule Engine to apply configurable data transformations but Drools can be used in any portion of your software. After all, rules are needed everywhere.
Velocity is a template engine and so the authors have been very careful to stop the developer from affecting directly the domain model. At the same time it is not declarative but imperative and so it can become as hard to read/maintain as Java when it comes to complex rules usually coming with several if levels. In addition at the time of this writing there is a wonderful Eclipse plugin that allows stepping through the code of Drool files. These are some of the good things about Drools. Drools come with a learning curve though and as with any other powerful tool the risks of using it wrong are high.
One of the reasons you want to move to a Rules Engine approach is that you want to eliminate your "spaghetti code" resulting from several nested "if statements".
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment