I want to create an app that uses a series of algorithms (increasing in complexity each time).
The way the app will work is like so...
1. Set the first algorithm as the current algorithm.
2. Check to see if the current algorithm has an effect.
----- a. No effect so set the next algorithm to be the current algorithm and run step 2 again.
----- b. Has an effect so continue.
3. Run the current algorithm and make the changes.
4. Changes made so stop running and wait to be triggered at the beginning again.
I can write the program fairly easliy by coding all the algorithms in to a class and hard coding the order.
However, I was wondering if there is some design pattern that can be used to make expandability easier.
How can I add another algorithm without having to hard code an additional bit into the loop would it be possible to store the function names in an array and use the strings as a reference to the fuction?
Also how can I change the order in which the algorithms run in the app itself (i.e. allow the user to define what order they run in)?
Whilst writing I've been thinking it may be possible to store them as objects that inherit a "go" method. Store the objects in an array and then retrieve them in order to first run a "check" method and then a "go" method.
So...
(N.B. I know the syntax is a bit all over th place language wise but take it as pseudo code).
The classes EasyAlgorithm and HardAlgorithm would both subclass Algorithm and override the "check" and "go" methods.
This way I could rearrange the order of the array quite easily by allowing the user to move them around. (not quite sure how exactly though).
All I need to do is create the algorithm and add a line of code to add it to the end of array.
Is that the best way?
Any other ideas?