We are using Java as a backend development language.
One year back, we wrote a method which uses switch cases based on Enums values. Since we are continuously adding enum members and according adding cases in the method, the method has grown to very large extent. Currently, we have around 100 enum fields and corresponding number of switch cases.e.g.
class AClass{
enum option{ o1, o2, o3...on}
Value method(Option o){
switch(o){
case o1:
value = deriveValue(p1,p2,p3);
case o2:
value = deriveValue(p2,p3,p4);
.
.
.
case on:
value = deriveValue(p1,p2,p3);
}
}
}
Thus each time a business requirement comes, we add enum and corresponding switch case. Now the method has become too long and looks unmanageable, if we keep on adding the same logic in future.
To clean, we thought of replacing switch case with polymorphism by creating classes for the same, but again, we will end up creating n number of classes.
We are looking for small, simple and manageable solution.
----------------- Update ---------------------
As suggested, to elaborate more, Enum values are fields names for which a client needs a value. Thus if a client need the value of a new field, we add the field in enum, and the corresponding definition of how to fetch value for the newly added field, by adding the corresponding switch case.
In the switch case, we have a common reusable method e.g. deriveValue() (Please refer to the example given) to which we pass parameters required for deriving the value for the newly added field.