avoiding if statements

前端 未结 24 785
心在旅途
心在旅途 2021-01-30 08:39

I was thinking about object oriented design today, and I was wondering if you should avoid if statements. My thought is that in any case where you require an if statement you ca

24条回答
  •  滥情空心
    2021-01-30 09:32

    I will say the answer is vaguely yes-ish. Especially when the language allows some heavy duty functional programming (ie C#, F#, OCaml).

    A component that contains 2 if statements strongly couples two business rules so break it up.

    Take that as a very general rule of thumb but I would agree. If you have a bunch of if statements, maybe you should think about another approach.

提交回复
热议问题