Hello All,
I'm sure this must be an easy one, but I'm a little stumped.
I have a rules engine that allows non-technical admins to create rules for
things like what page template to use for a given page request. The rules
support nesting and precedence with an if/then/else construction. They are
stored in the database and may operate on any variables that the user might
want to interact with. A simplified example might be:
If night time
Use template A
Else
If UserRole = Admin
Use Template B
Else
If PageID = 12
Use Template C
/If
/If
/If
I have no control over the rules as they will be managed in the database
long after I have stopped coding the application. Implementing this
procedurally was trivial. As long as I had a syntax for storing the rules in
a database and a web based "rule builder", implementing the rules was easy -
I just needed a global list of variables and to generate the logic at design
time (using code generation). Unlimited flexibility, great performance.
How do I do this in an OO way? I suppose I could have a rules object,
document what object properties would be public and inviolable (as part of
an external contract with the non technical users - a list of variables they
could always count on an implementation of so their rules would always work)
and could generate methods for all of the key rules based decisions with the
methods returning the method to call or the variable to use.
I'm not a big fan of that approach. I don't like public object variables
(with or without getters and setters). I like to keep my objects nice and
shy - trusting them to do things rather than to share properties allowing
those things to be done anywhere, but for a generic rules engine where I
don't know what combination of request, user, page or other variables could
be combined within a single rule, I'm not quite sure how to proceed.
That said, I'm still struggling through chapter 1 of Head First Design
Patterns, so if anyone has gotten to a later chapter and has already got the
answer, a page number would be much appreciated :->
Best Wishes,
Peter
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
[email protected] with the words 'unsubscribe cfcdev' as the subject of the
email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.com).
An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]