Recently I have written a rules engine for a very large menu system in an application I work on. Many of the rules apply many items, so I didn't wish to have to express the same rule many times. To avoid this, the rule engine DSL was born:
And rules are rolled together, so a specific menu item must have all of its rules evaluating to true to be displayed.
The problem arose when an item was displaying when it shouldn't (or vice versa). Debugging with rules specified like this was a pain, and when I saw the article about ExpressionRules by Daniel Wertheim, I thought it would help solve my problem. He replaces Lambda conditions with a class and implicit operator, allowing code to be changed from something like this:
To something like this:
He does this using a base class and then inheriting from it to create the rule:
I took his base class and modified it to this:
This means the IsBonusCustomer now becomes this:
Not only do we still have the readability of the first version, but a full function that can have logging added to it, and easier debugging.