I have a problem using switch statement when I tried to deal with a special situation. For example, I have 3 cases: A, B, C.
I often find introducing enum
s adds clarity. Here I imagine each enum
is an issue which can be resolved through a number of processes:
enum Issue {
A {
void handleIt () {
statement_1();
statement_3();
}
},
B {
void handleIt () {
statement_2();
statement_3();
}
},
C {
void handleIt () {
// Do nothing.
}
},
D {
void handleIt () {
A.handleIt();
B.handleIt();
}
};
abstract void handleIt();
}
Note here that you get the added benefit of being able to handle certain issues using the solutions of other issues (see my D
enum
).