I wanna design a rule engine to filter incoming objects as follow:
At the beginning, I have three different classes: A, B, C. The list of classes is dynamic, i.e: I wanna extend this to work with class D, E, etc if D and E will be added later.
public class A {
int a1;
String a2;
boolean a3;
Date a4;
List<String> a5;
...
}
public class B {
String b1;
boolean b2;
Date b3;
long b4;
...
}
public class C {
String c1;
boolean c2;
Date c3;
long c4;
...
}
There will be different objects of class A, B, or C that are gonna be filtered by my rule engine.
The users can define different rules based on a set of predefined operations that each member variable of a class can possibly have.
An example of some operations:
- a1 can have operations like: >=, <=, or between some range, etc.
- a2 can have operations like: is not, or is, etc.
- a3 can only be true or false.
- a4 can be: before certain date, after certain date, or between, etc.
- a5 can be: exists or not exists in the list, etc.
Some example rules for an object of class A would be:
- a1 is between 0 and 100, and a2 is not "ABC", and a3 is false, and a4 is before today, and a5 contains "cdf", etc.
- a2 is "abc", and a3 is true, and a4 is between some date range.
- etc.
One bullet is one rule. In a rule, there can be one criterion or more criteria (multiple criterion's that AND's together).
Each criterion is defined by a member variable with an operation that I can apply on that variable.
The rule engine must be able to process rules defined by users for each object of class A, B, or C. For every rule (A Rule, B Rule, or C Rule) coming in, the return will be a list of objects that matched the specified rule.
I can create Criterion, Criteria, ARule, BRule, CRule, Operation objects, etc; and I can go with the Brute Force way of doing things; but that's gonna be a lot of if...else... statements.
I appreciate all ideas of any design patterns/design method that I can use to make this clean and extendable.
Thank you very much for your time.
Aucun commentaire:
Enregistrer un commentaire