Map<String, Selection> selectionMap = new HashMap<>();
selectionMap.put("RawFitnessSelction", new RawFitnessSelction());
selectionMap.put("RouletteWheelSelection", new RouletteWheelSelection());
selectionMap.put("TournamentSelection", new TournamentSelection());
AbstractSelectionFactory asf = new DOSInputSelectionFactory(
selectionMap,
"Input choice of selection method: ");
class Client {
AbstractSelectionFactory asf;
Client (AbstractSelectionFactory asf) {
this.asf = asf;
}
public void select(Map<String, Double> population) {
Selection selection = asf.chooseSelection();
...
}
An abstract factory can be passed to a client and called as many times as you like, or just once. So long as the Client never sees the abstract factory being built, it doesn't care if you're getting input from the command line, a GUI, a file, a database, the internet, or whatever else.