avoiding if statements

前端 未结 24 776
心在旅途
心在旅途 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:41

    I agree with Vance that the IF is not good, because it increases the conditional complexity and should be avoided as possible.

    Polymorphism is a totally viable solution at condition it's used to make sense and not to "Avoid If".

    A side note that does not fit to your OOP requirements but the Data Oriented approach also tends to avoid the branching.

提交回复
热议问题