Hi,
I have a query on a design question.
The requirement is as follows:
I have to develop a generic rule service. My application has list of possible rules as components (say Rule1, Rule2, Rule3, Rule4, Rule5, Rule6, Rule7 and so on). Based on user input I have to trigger one or more of these rules. e.g
If input=1 then trigger Rule1, Rule2, Rule3
If input=2 then trigger Rule1, Rule2, Rule4
If input=3 then trigger Rule1, Rule2
If input=4 then trigger Rule5, Rule6, Rule7
and so on.
I have designed all rules to be implementing same interface(say RuleInterface).
RuleInterface has a single method as follows - execute()
My design approach is as follows:
Develop a RuleProcessor
which will have a attribute - Collection<Rule> ruleCollection
and a method process(int input) which will iterate each rule from rules and execute it.
My query is how do I design the set-up of ruleCollection attribute.One design I could think of is to populate all rules combination in DB and then use it to populate the ruleCollection attribute. Thus given above requirement, we will have 4 entries in DB (one for each input value). Is there a better and simple design possible(I am sure there is). I am tending to look at a design solution which is java based (and not necessarily dependent on DB) but am open to all the suggestions. I am using spring framework so if spring provides something out of the box then I would prefer that.
Thanks,