I am aware of how to replace a switch statement through polymorphism, like it is explained for instance here.
In my case however I have two Enum:
public enum EleType {
INTEGER,
CHARACTER
}
and
public enum SorterType {
BUBBLE,
INSERTION
}
and the switch/if I would like to refactor has the structure:
if ( eleType == EleType.INTEGER ) {
switch ( sorterType ) {
case BUBBLE:
composition = new SorterComposition<Integer>(new BubbleSort<Integer>(), randomList);
break;
case INSERTION:
composition = new SorterComposition<Integer>(new InsertionSort<Integer>(), randomList);
break;
}
} else if ( eleType == EleType.CHARACTER ) {
switch ( sorterType ) {
case BUBBLE:
composition = new SorterComposition<Character>(new BubbleSort<Character>(), randomList);
break;
case INSERTION:
composition = new SorterComposition<Character>(new InsertionSort<Character>(), randomList);
break;
}
}
Because both enum appear together and both affect the SorterComposition part, I am unsure how to refactor this structure. Also I am unsure how to get the "Integer"/"Character" generic types from EleType.INTEGER or EleType.CHARACTER respectively without using conditional statements.