In my program, I need to check if a variable equals 1, 2 or 3 and depending on the result, perform a different method:
if (phase.equals("1")) {
PhaseOne.performPhase(inputParser.getSource(), inputParser.getTarget());
} else if (phase.equals("2")) {
PhaseTwo.performPhase(inputParser.getSource(), inputParser.getTarget());
} else {
PhaseThree.performPhase(inputParser.getSource(), inputParser.getTarget());
}
This code is so simple and basic but I really don't like it. Of course I could use switch conditions but it would, in my humble opinion, just display the same basic function in a different way.
My question is: is there a way to implement the function in an elegant and expandable way?
FYI, I already red this post but I did not find an answer which fits to my question.