Hi,
Which alternative you elect depends upon how *you* want to use Drools.
Rules externalise application logic from the code-base; the degree of the separation is down to you.
If in doubt use Drools :) the flexibility of externalising various operations could pay dividends when you come to maintain the application at a later date.
If runtime performance of rules is important (i.e. using "from" could represent an issue as implied by Mauricio Salatino) why not load facts into Working Memory using a set of "bootstrap" rules first. This is in essence equivalent to your proposed use of the Globals in your Alternative B (I assume you'd use the Global to load facts into WM with a set of low salience rules first).
If rules are to be authored by non-technical people you could look into using a DSL to abstract some of the lower level syntax away form the rule author.
Just my 2 cents in addition to Mauricio's - that makes 4 cents now - keep on like this and you'll be able to retire early ;)
Cheers,
Mike
Hello everyone
In my company we are planning to use Drools for couple of projects and we having some questions about the best way to use it
My question is what should be and shouldn't be done inside a Rule Condition/Consequence. Given that we can write Java directly or call methods (for example From a Global object in the Working Memory).
Example. Given a Rule that evaluates a generic Object (e.g. Person) have property set to true. Now, that specific propertie can only be defined for that Object going to the database (or going to a web service) and fetching that info. So we have two ways of implementing that:
Alternative A:
- Go to the database and fetch the object property (true/false, a code)
- Insert the Object in the working memory
- Evaluate the rule
Alternative B:
- Insert a Global Object that has a method that connects to the database and check for the property for the given object.
- Insert the Object to eval in Working Memory
- In the rule, call the Global Object and perform the access to the database
Which of those is considered better? I really like A, but sometimes B is more straightforward, however what would happen if something like a Exception from the Database is raised? I have seen the alternative B implemented in the Drools 5.0 Book from Packt Publishing,however they are doing a mocking and they don't talk about the actual implications of going to the database at all.
Thank you in advance,
--
Miguel Fernando Cabrera Granados
http://mfcabrera.com
"A los hombres fuertes les pasa lo que a los barriletes; se elevan cuando es
mayor el viento que se opone a su ascenso." - José Ingenieros
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users