I have a class (Activity) in an android application that has a bunch of example math problems on it. You can move to a different question by pressing a button which changes a question counter and displays a new question. You can see how to solve a question by clicking a 'show work' button, which displays a bunch of information on the screen. My problem is I have a bunch of methods that look like this:
public void showWorkButtonClicked()
{
if (questionCounter == 1)
showWork1();
else if (questionCounter == 2)
showWork2();
else if (questionCounter == 3)
showWork3();
//for how ever many questions are available
}
Obviously these if-statement are terrible design. I could store the data needed for each function in a class, which might work in this case (but would probably just make things confusing), but what if each showWork method was sufficiently unique to make this impractical. I know if I was making the app in C#, I could simply put delegates into a list and would have an elegant solution. If anybody has a better solution (that ideally uses less code), I would love to hear it.