Hi my fellow experts, may be you guys could help me and feed a food for thought. I am designing a complex application that requires some thing to be executed on-the-fly like a plug-in.
The problem is the application should be highly configurable and the rule-based application is all driven by config file determining what and when to run. The plug-in list that need to run would be supplied in the config file like,
plugins=Rule1, Rule2, Rule5, Rule6
Reading the above text, only the rules Rule1, Rule2, Rule5 and Rule6 objects are picked up for the application process.
Keeping the rule in mind, "no change in the code" and highly configurable though a rule-based simple text (config) file, the rule classes/objects are to be picked up dynamically based on the list provided like above.
My design is to have a Register class which maintains a list of rules (objects) registered and executes for a particular model/process dynamically. Although my initial thought to define a Base class for the Rules class so that all the plug-in style rules would derive from and execute through the base class type pointer dynamically, am not having enough thought of how to read the constants from config file and invoke respective rule objects.
I also had a thought to design the Rule class to register with its object's address or a pointer to its function, and a function to invoke it as needed on-the-fly but the object requires to be instantiated dynamically someway, HOW???
The scenario of my initial thought of design is some thing like;
Config file (a plain text file):
|
rules=Rule2, Rule4, Rule7
|
The class Register would look like
1 2 3 4 5 6 7
|
class Register
{
public:
bool register(RuleBase *plugin_rule); // would be a list or vector of registered plug-ins
bool registered(id); // checks if the rule is in registered list/vector
invoke(string id); // invokes the rule.process() one after another all registered
};
|
The Register's invoke() would be called from main application during run-time to process only the registered (ie, listed in config file) rule (objects).
The rule of thumb is to not to change the code when the application is run for different models/departments. A simple change in the config file should fulfil the model's requirements.
Thought to implement the design pattern, Command (with Functor), but not sure how to read the text file and invoke the relevant on-the fly.
Any ideas or food for thought would be really appreciated.
PS: It is NOT in windows env.
Thanks a lot.