Is Switch (Case) always wrong?

后端 未结 8 837
情歌与酒
情歌与酒 2020-12-19 00:37

Are there instances where switch(case) is is a good design choice (except for simplicity) over strategy or similar patterns...

8条回答
  •  半阙折子戏
    2020-12-19 01:01

    First of all, Simplicity often is a good design choice.

    I never understood this bias against switch/case. Yes, it can be abused, but that, so can just about every other programming construct.

    Switching on a type is usually wrong and probably should be replaced by polymorphism. Switching on other things is usually OK.

提交回复
热议问题