keep separate components for separate things - do one thing and do it well / separation of concerns.
Your console thing probably doesn’t require input etc. There are a couple of different approaches that work and there isn’t really a consensus about what’s best. Have a look at GoF and not just the MVC cause that can be implemented a zillion ways. But the idea of how complex components are just a collection of simple components.
I think I get where your going, being ‘smart’ doesn’t necessary work well and will spin the complexity out of the control.
update:userName
remove:userName
u:username might look like a good idea but there are pretty much only 26 options for identifiers going from update to u throws human readability out the window so why stick to ‘u’ at all then? you might as well use numbers (IRC is based on this if I remember correctly.) but note that it is performance optimization (which might well be premature) and is an implementation detail that shouldn’t spread in your code.(which is a code smell,to use a hip word)
enums work well and also it allows you to use in a switch
public class Protocol {
enum MessageType {
AddUser(1),
RemoveUser(2);
private final int indentifier;
private MessageType(int indentifier) {
this.indentifier = indentifier;
}
public MessageType getMessageByInt(int indentifier) {
for(MessageType type : values()) {
if(type.indentifier == indentifier) return type;
}
return null;
}
}
}