What's the best alternative to an out of control switch statement?

后端 未结 11 1440
悲&欢浪女
悲&欢浪女 2021-02-14 14:20

I have inherited a project that has some huge switch statement blocks, with some containing up to 20 cases. What is a good way to rewrite these?

11条回答
  •  一生所求
    2021-02-14 14:55

    if it's working without major bugs (by not major I mean they don't make you pull your hair out) why bother refactor it? Don't refactor everything.

    If you want, you can change it to polymorphism, but this will be a shotgun surgery, you'll probably have to refactor a whole lot more than just this switch block.

提交回复
热议问题