Skip to content

Instantly share code, notes, and snippets.

@pumpkincouture
Created March 24, 2015 15:18
Show Gist options
  • Save pumpkincouture/7586b33f3252820c2408 to your computer and use it in GitHub Desktop.
Save pumpkincouture/7586b33f3252820c2408 to your computer and use it in GitHub Desktop.
# Choice Interface with command method
public interface Choice {
public int getConfigurationChoice();
}
# Class implementation of Interface
public class BoardSize implements Choice {
private CommandLineInterface ui;
private int boardChoice;
private ChoiceValidator choiceValidator;
public BoardSize(CommandLineInterface ui) {
this.ui = ui;
}
@Override
public int getConfigurationChoice() {
ui.promptForBoardSize();
validateBoardSizeChoice(ui.captureChoice());
return boardChoice;
}
}
# New Input Collector
public class MenuFactory {
private List<Integer> gameValues = new ArrayList<>();
public void collectUserInput(List<Choice> gameOptions) {
for (Choice choice : gameOptions) {
gameValues.add(choice.getConfigurationChoice());
}
}
public List<Integer> getUserValues() {
return gameValues;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment