My project is going to be compiled with a bunch of legacy code (as >100 independent methods). All the different legacy methods are going to serve the same purpose in my project, they just do so differently. That is to say, they all have roughly the same inputs and the same outputs, but they do some very complex calculations to get those outputs, and those calculations can vary greatly between the different methods. I expect to only have to call one of the methods during a given session, but the next session may need to call a different method. In my project, when I am about to call one of the methods, the user will have entered enough information for me to be able to determine which method to call.
One way I could handle this would be with a huge if
block. I would have to check against a couple different conditions. For each combination of conditions, I would call a different one of my legacy methods. The problem with this approach is that it would be very bad from a readability point of view - the actual if block would probably end up being 100s of lines long. I imagine there could also be some performance issues with that many different else-if statements as well.
What I would like to do is create a look-up table, where I store the name of the method to call (as a string), and pair that with the different conditions I need to check against. My company is trying to shift its policy towards using more look-up tables and fewer of the huge if
blocks.
Is there a way to call a method based on the "method name" string that I'm getting back from my look-up table? If so, what would the syntax look like for doing something like that? Or are there other (better) ways to handle this that I haven't thought of? Or is the huge if
block actually more in line with best practice?