Answer by Anon for Refactor java code
You say that you're processing input from a socket. How much input? How complex is it? How structured is it?Depending on the answers to those questions, you might be better off writing a grammar, and...
View ArticleAnswer by Itay Maman for Refactor java code
Building the Command patten upon an enum class can reduce some of the boilerplate code. Let's assume that x in input.equals(x) is "XX" and y in input.equals(y) is "YY"enum Commands { XX { public void...
View ArticleAnswer by Instantsoup for Refactor java code
How about interfaces, a factory, and a little reflection? You will still need to handle exceptions on bad input, but you would always need to do this. With this method, you just add a new...
View ArticleAnswer by Romain for Refactor java code
One way could be to have an interface ICommand that is the general contract for a command, e.g.:public interface ICommand { /** @param context The command's execution context */ public void...
View ArticleAnswer by BalusC for Refactor java code
Collect those commands in a Map<String, Command> where Command is an interface with an execute() method.Map<String, Command> commands = new HashMap<String, Command>();// Fill it with...
View ArticleRefactor java code
Okay guess this question looks a lot like:What is the best way to replace or substitute if..else if..else trees in programs?consider this question CLOSED!I would like to refactor code which looks...
View Article
More Pages to Explore .....