creating a simple rule engine in java

Implementing a simple rule-based evaluation system in Java isn’t that hard to achieve. Probably the parser for the expression is the most complicated stuff. The example code below uses a couple of patterns to achieve your desired functionality. A singleton pattern is used to store each available operation in a member map. The operation itself … Read more

Rules Engine – pros and cons

Most rule engines that I have seen are viewed as a black box by system code. If I were to build a domain model, I would probably want certain business rules to be intrinsic to the domain model, e.g. business rules that tell me when an object has invalid values. This allows multiple systems to … Read more

How to implement a rule engine?

This snippet compiles the Rules into fast executable code (using Expression trees) and does not need any complicated switch statements: (Edit : full working example with generic method) public Func<User, bool> CompileRule(Rule r) { var paramUser = Expression.Parameter(typeof(User)); Expression expr = BuildExpr(r, paramUser); // build a lambda function User->bool and compile it return Expression.Lambda<Func<User, bool>>(expr, … Read more