How to avoid many 'if's' and provide runtime params on execution
问题 I am trying to avoid lots of if's and use an OOP way to execute different executions. the execution is determined by ACTION integer which I get from an API on runtime. I though about command pattern and this is how it looks: I created on Spring configuration a hashmap: @Bean public HashMap<Integer, Command> hashmapCommands() { HashMap<Integer, Command> supportedCommands = new HashMap<>(); supportedCommands.put(command.action.getId(), myCommand()); .. } @Bean public Command MyCommand() {