I have a very long switch
statement which is expected to have nearly 50-55 cases'
switch (commandType) {
case COMMAND_LOGIN:
command = getCommand(commandType, agentId);
break;
case COMMAND_MAKE_READY:
command = getCommand(commandType, agentId);
break;
case COMMAND_MAKE_NOT_READY:
command = getCommand(commandType, agentId);
break;
case COMMAND_MAKE_NOT_READY_WITH_REASON:
command = getCommand(commandType, agentId);
break;
case COMMAND_LOGOUT_WITH_REASON:
command = getCommand(commandType, agentId);
break;
case COMMAND_ANSWER_CALL:
command = getCommand(commandType, agentId);
break;
case COMMAND_HOLD_CALL:
command = getCommand(commandType, agentId);
break;
case COMMAND_RETRIEVE_CALL:
command = getCommand(commandType, agentId);
break;
case COMMAND_END_CALL:
command = getCommand(commandType, agentId);
break;
case COMMAND_TRASFER_SST_CALL:
command = getCommand(commandType, agentId);
break;
case COMMAND_CONSULT_CALL:
command = getCommand(commandType, agentId);
break;
.
.
.
.
.
default :
command = "";
break;
}//end switch
It doesn't seem to be something which should exist in this current form, I have gone through some questions here 'but they doesn't seem to help in this condition' I have seen the "strategy pattern", but that also seems to be suitable for the case where i have to execute different method for every case. Kindly guide me how the size of this code can be reduced'
command = getCommand(commandType, agentId);
. Also, this place is about reviewing real code, not some kind of idea. – Josay 2 days agocommand
to be calculated differently depending on which case you are in. – skiwi 2 days ago