Yeah, I skimmed that article a while back. I didn't quite get the
point. I understand how plain Java objects can implement business
rules. And I understand how, if you need to trigger some processing
asynchronously, you can use MDB's. And of course the logic in the MDB's
could be business rules. Didn't seem that earth shattering though. And
in general, I wouldn't want to incur the expense of a distributed
business rules engine (data transfer objects, the whole nine yards)
except in cases where I really needed to.
Post by christoferjenningsCould you give more detail about getting the right domain object into
the rules context?
Post by christoferjenningsThis may be a dumb question, but how did you come to see it as the
interesting bit?
Let's say I have an order class, that delegates to a policy, or
specification, for its validation rules:
class Order {
private OrderValidator orderValidator;
public void validate() throws ValidationException {
orderValidator.validate(this);
}
public double total() {...}
public String placedBy() {...}
}
I want to implement OrderValidator via a rule. The rule will depend on
the order. In Drools it might look something like this:
<rule name="OrderValidator">
<parameter identifier="order">
<java:class>com.acme.Order</java:class>
</parameter>
<java:condition>order.total() > 1.00 &&
order.placedBy().equals("Fran")</java:condition>
<java:consequence>throw new ValidationException("Credit checked
failed");</java:consequence>
</rule>
To run that rule, I might have to do something like this:
class DroolsOrderValidator implements OrderValidator {
public void validate(Order order) {
WorkingMemory workingMemory = getWorkingMemoryFromDrools(...);
workingMemory.assertObject(order); // make the rules engine aware of
the order
workingMeomry.fireAllRules();
}
}
I guess I'd use dependency injection to plug the DroolsOrderValidator
into the order. Come to think of it, I guess it's not that bad after
all!
We're using Hibernate, which provides callback methods for interesting
events like inserting, updating, or deleting entities. So I guess we
could provide a hook that would assert all changed entities into the
Drools working memory, fire all the rules, and roll back the transaction
if there were any errors. The rules could be validation rules, or
integration type rules -- i.e. the consequences might be to send an
email whenever a particular entity is updated; send a message to another
system; sync some data with a legacy system, etc. Drools allows you to
invoke normal Java code from a rule, so the integration logic wouldn't
have to be coded in the rule, just the conditions as to when to fire off
the integration code.
Steve
-----Original Message-----
From: christoferjennings [mailto:***@yahoo.com]
Sent: Sunday, December 19, 2004 3:14 PM
To: ***@yahoogroups.com
Subject: [domaindrivendesign] Re: rules engines
Steve,
Thanks for pointing out the pages in DDD. I don't have the book with me.
:-(
Have you seen this article?
http://www.theserverside.com/articles/article.tss?l=RuleBasedMDB
The author shows a way to implement rules in plain java and describes
how it might work with message driven beans. I just don't know what to
make of it yet....
For my project, I think we could get the funding for JRules (there's a
real push to "leverage BEA" that would support it and a desire to not
use open source (that I don't agree with)) but like you said we've got
to come at it skeptically, with an open mind. I don't know if we have
the time for the learning curve of JRules. I also don't know if we have
the time to develop a Specifications-like approach. (sigh) Thank you for
bringing up the Ubiquitous Language. It does seem like that will be the
key. Fortunately I think there is a pretty well developed language in
the stocks department. Unfortunately it is not well documented and we
software designers haven't learned it yet.
On a nuts and bolts level, I just don't want to promote a design or tool
that pushes us away from a rich object model for the domain. (That's my
personal preference, that the richest reflection of the domain be in
OO.) On the other hand, I want to promote the best solution I can think
of. This discussion is helping a lot to figure out if rules engines are
in it.
Could you give more detail about getting the right domain object into
the rules context?
This may be a dumb question, but how did you come to see it as the
interesting bit?
Thanks!,
boz
Post by christoferjenningsI'm interested in this topic as well, as we're looking into using a
rules engine on my new
project. Eric discusses integrating rules engines with a domain model
Post by christoferjennings1. Be skeptical. On my project, we'll need to make sure that we
aren't just introducing a
rules engine for the coolness factor, or because we never really applied
OO. Eric explains how to represent less obvious kinds of objects in
chapter 9, for example specifications, in standard OO languages. And
there's benefits to sticking with one paradigm - no impedence
mismatches.
Post by christoferjenningsNevertheless, I have worked on similar projects at my company where a
rules engine
seemed appealing; we just never got around to investigating. So I'm
glad this team is looking into it. I hope to learn something.
Post by christoferjennings2. Lean on the ubiquitous language. Using the same terms should help
unify and
connect the domain model with the rules.
Post by christoferjenningsMy thought is that rules are one way of implementing policies. I
think your example of
using a rules engine as a way to implement a policy is very good. I
think you nailed the main issue with your last point - with a domain
model, domain objects have rules; with a rules engine, rules have domain
objects. Hopefully using the ubiquitous language will help bridge the
gap. We're looking into Drools, which allows for a fairly tight
integration between Java code and rules. Rules can refer to Java
objects, and methods or properties on those objects. But of course you
lose some portability.
Post by christoferjenningsOur tentative plan is to do just as you described. We'll treat create
Java interfaces for
our policy objects, implement the policies via the rules engine. So the
rest of domain model doesn't know or depend on the rules engine
directly. The interesting bit is how to
pass the right domain object to the rules engine context, for it to
operate on. Any
thoughts there?
Post by christoferjenningsSteve
-----Original Message-----
Sent: Sun 12/19/2004 12:33 PM
Subject: [domaindrivendesign] Re: rules engines
Good point Zhiyi. I agree completely that the business logic should be
platform independent. I'm pushing for us to use a DDD approach with
business logic in plain old java objects (POJOs) to keep from getting
to tied to WLI. Hopefully we can find a good balance between
short-term productivity and maintainability.
Post by christoferjenningsSince my first post I've done a little digging into rules engines. In
the java world, there
are
Post by christoferjenningssome basic standards (JSR 94) and there are open-source and
proprietary engines. It
turns
Post by christoferjenningsout the WLI does not have a real engine but promotes using ILOG's
JRules. Of course this gets us back to the platform question. It seems
tome that if you use Jess or DROOLS or JRules etc. then the rules will
be pretty much tied to the engine. We'll have to consider
the
Post by christoferjenningstrade-offs there.
Another thing I noticed is that rules seem kind of like the
Specification pattern in DDD.
Post by christoferjenningsMay it's better said that Specification might be a way to implement a
rules engine. I
don't
Post by christoferjenningswant to implement a rules engine if I don't have to, so now I'm
wondering if a rules
engine
Post by christoferjenningscould be used like Specification. That is, in a domain object that
needs rules, maybe the rules engine (or a set of rules) could be
injected. Then the domain objects behavior
would
Post by christoferjenningsbe governed by the rules.... And that's as far as my brain has got so
far :-)
The little I've read about rules make me think the paradigm is the
opposite: Instead of domain objects having rules, rules are supposed
to have domain objects. Can the two ideas work together? Or does
declarative programming force a different approach to domains that is
not based on rich object models but on rich rules models?
Post by christoferjenningsHmmm.
,boz
Post by Zhiyi ZhangI don't have any experience with rules engines, but for one thing,
I'd make domain business logic platform-independent as much as
possible.
Post by christoferjenningsPost by Zhiyi ZhangI understand that some platforms may help you develop your business
domain, however, all platforms have limitations and restictions. You
need to understand whether the platform meets your requirements.
Secondly, you need to maintain a good guidance on how to use the
platform. I've often seen that platform adds additional complexity
which makes business logic hard to understand, to maintain, and to
enhance, as software life-cyle goes on. Lastly, but not least
importantly, it's a much less pain to replace one platform with
another one if your domain business logic is platform-independent.
My $.02.
- z
On Sat, 18 Dec 2004 22:58:20 -0000, christoferjennings
Post by christoferjenningsHas anyone in this group used rules engines with DDD?
I'm just starting work on a custom J2EE stock trading application
where employees
can
Post by Zhiyi ZhangPost by christoferjenningspurchase and sell stocks of their company periodically. At first
glance it seem slike
it
Post by christoferjenningsPost by Zhiyi ZhangPost by christoferjenningsshould be simple but I've been told that there is a lot of
complexity driven by
business
Post by christoferjenningsPost by Zhiyi ZhangPost by christoferjenningsrules. The rules have evolved over years at the company, and I
don't understand
them
Post by christoferjenningsyet.
Post by Zhiyi ZhangPost by christoferjenningsOn the project, there seems to be a feeling (or hope anyway) that
the Weblogic
Integration
Post by Zhiyi ZhangPost by christoferjenningsPlatform (WLI) can be used to capture business rules in a visual
way that business
analists
Post by Zhiyi ZhangPost by christoferjenningscan modify them. Has anyone in this group used WLI or other rules
engines as part
of
Post by christoferjenningsa
Post by Zhiyi ZhangPost by christoferjenningsdomain driven design effort? or have any suggestions on good books
(hopefully
thin
Post by christoferjennings;-) to
Post by Zhiyi ZhangPost by christoferjenningslearn how to work effectively with rules engines?
Thanks in advance.
,boz
Yahoo! Groups Links
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/NhFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/NhFolB/TM
--------------------------------------------------------------------~->