What is the best way to replace or substitute if..else if..else trees in programs?

后端 未结 21 1189
迷失自我
迷失自我 2020-11-28 06:23

This question is motivated by something I\'ve lately started to see a bit too often, the if..else if..else structure. While it\'s simple and has its uses, somet

21条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 07:14

    In OO paradigm you could do it using good old polymorphism. Too big if - else structures or switch constructs are sometimes considered a smell in the code.

提交回复
热议问题