Back in a different geological epoch I built a lot of expert systems. I'm a little rusty, but I think I can say that the system I used the most (TIRS), was a "frame-based" kind of system. Maybe not truly frame-based, but at least kind of frame-based. By "frame-based" I mean a system where you could create class-like templates (frames) and then instantiate them. Then, you could write "rules" that could take the general form:
if there exists an instance of frame X and if there exists an instance of frame Y and if there exists an instance of frame Z such that X.a == Y.e and X.b == Z.m and Y.f == Z.n
then do stuff...
Sometimes it felt almost like weird, in-memory SQL queries.
Anyway, I have a Java app. where I need to create a lot of rules (maybe 25 to 50 rules?), like the one I showed above. A really horrible way to do it is to create nested loops (foreach X, Y, Z). I've written a few of those "rules" and they kind of make me throw up in my mouth a little
In my case, I think it's okay to hard code the order in which these rules will "fire" (be executed).
So the question is, is there a cleaner, fairly lightweight way to implement rules like this as a part of a larger Java app?
I remember looking at Jess a long time ago and feeling like it was very capable, but also probably not very lightweight from either a performance or "brain investment" perspective. Maybe I'm wrong about that?
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
I guess I posted this here because I'm wondering whether there is some sort of OO or patterns approach to this kind of design that I'm not familiar with. I'd really rather not go down any sort of "rules engine" approach if I can help it. These so-called "rules" are going to have to be executed thousands of times during an interaction.
However it would be difficult in a case like this to tell where you cross the line towards building your own microworld expert system/rules engine - at which point using a more general pre-existing implementation would make more sense.
I recently caught a presentation on JESS at a Java conference. At first blush, I would consider a rules engine.
The 2 dominant ones seem to be JESS and Drools. JESS is based on older technology, and uses a Lisp-like syntax for the rules. However, the speaker said that it can execute 80K rules/second, so performance may not be a problem.
On the other hand, here is an entry-level article on Drools:
On the _other_, other hand, I too have wondered about basic OO pattern that might work in simple instances. Imagine a Predicate interface like so:
A CompositePredicate could chain together individual predicates, where each one contains a given "rule". Things get a bit muddy here but I'm thinking of the composite pattern combined with a "filter" pattern. It is hard to tell if this would fit your situation.