I want to not repeat a specific piece of code and need advice on how to structure it better
public static final int TAB_A= 0;
public static final int TAB_B= 2;
public static final int TAB_C= 3;
public static final int NO_TAB = -1;
public String getTabName() {
switch (getTabId()) {
case TAB_A:
return "TA";
case TAB_B:
return "TB";
case TAB_C:
return "TC";
default:
return "NT";
}
}
public string execute() {
setResults(getTabName());
}
public int getUserCount() {
SomeVO vo = (SomeVO) getFirstResultSet().get(0);
switch (getTabId()) {
case TAB_A:
return vo.getTabAResults();
case TAB_B:
return vo.getTabBResults();
case TAB_C:
return vo.getTabCResults();
default:
return vo.getSomeStuff();
}
}
I'd like to able to consolidate the logic in getTabName()
and getUserCount()
methods.
Having switch statements checking for the same thing doesn't seem efficient, but they are returning two different things....