I've inherited some code and within it is a 500 line switch statement. Basically, it switches on a string
task and executes the corresponding actions.
I have since moved each case statement in to their own method in a new class. The giant switch statement still exists but instead of inlining the logic each case just calls a method so it's much neater.
The problem is that the methods modify a lot of different things. 50% of the methods require 0 arguments passed in. Some 40% require 5 arguments and the remaining 10% require 10 arguments each.
Currently this works but I'd like to make it better. Either get rid of the switch statement or lower the amount of passed in parameters somehow.
I was thinking of using a Dictionary
that mapped string
s to Action
s to eliminate the entire switch, but this wouldn't work because I'm using a lot of ref parameters (primitive types) and there'd be no way to pass those in to the constructor and have them later be referentially modified.
The obvious solution to that problem is just to place all 16 or so variables in to a separate class and pass that but a lot of them aren't very related so it just replaces one problem with another (long parameter list with non-cohesive data class).
Was wondering if there were any other ways to improve this code. Thanks for reading.