In the application I am developing I am facing a situation; I want to know if there is a design pattern for this. It's as follows
- User is presented on a web interface with different algorithms for a process
- User selection is stored in the database.
- Now, the application should perform computations differently depending on the algorithm selected.
What is a good strategy to implement this? Right now what we are doing is -
- Have a reference DB table which has all the algorithm types and the corresponding class names in code (eg. If quick sort algorithm then we store QuickSort). This has to be manually updated everytime a new algo comes
In the code, get the algorithm type and use reflection to instantiate the appropriate algorithm type. In C# we use code similar to below
System.Reflection.Assembly types = System.Reflection.Assembly.LoadFile(System.Reflection.Assembly.GetExecutingAssembly().Location.ToString());
foreach (Type t in types) if (t.Name==classname) createinstanceof(t) //classnames is the list of all the class types that is loaded from reference table in DB.
My gut feeling is there should be a simpler/better way to do this as it seems a very standard problem. I know the strategy pattern - but what I want is to simplify and possibly remove manual tasks.