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

后端 未结 11 1414
悲&欢浪女
悲&欢浪女 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 15:05

    Polymorphism. But it may not be a trivial refactoring.

    Some examples and refs:

    Refactoring (Googe books)

    Switch Statement code smell and Polymorphism

    Refactoring switch-statements

提交回复
热议问题