Refactor java code
Posted
by Alfred
on Stack Overflow
See other posts from Stack Overflow
or by Alfred
Published on 2010-03-31T20:15:10Z
Indexed on
2010/03/31
20:23 UTC
Read the original article
Hit count: 495
java
|refactoring
I would like to refactor code which looks something like this:
String input; // input from client socket.
if (input.equals(x) {
doX();
} else if (input.equals(y) {
doY();
} else {
unknown_command();
}
It is code which checks input from socket to perform some action, but I don't like the if else
construction because every time a new command is added to the server (code) a new if else has to be added which is ugly. Also when deleting a command the if else
has to be modified.
© Stack Overflow or respective owner