i am using enums as alternative for 250+ cases inside switch.
switch(variable){
case "NAME":
case "MIDDLE":
case "LAST":
return a();
break;
case "SUFFIX":
case "PREFIX":
return b();
break;
}
I have problem in handling the above situation while using enum.
public enum Action {
NAME {
@Override
public String getVariableData() {
return a();
}
},LAST {
@Override
public String getVariableData() {
return a();
}
},MIDDLE {
@Override
public String getVariableData() {
return a();
}
},SUFFIX {
@Override
public String getVariableData() {
return b();
}
},PREFIX {
@Override
public String getVariableData() {
return b();
}
};
public abstract String getVariableData();
}
Here NAME,MIDDLE,LAST returns same value. But my question is why i need to implement saperately and how to reuse the existing implementation. Please Help me to reduce the code my reusing the existing implementations.