How to avoid multiple nested IFs

前端 未结 6 551
情话喂你
情话喂你 2021-02-01 19:08

I am currently trying to restructure my program to be more OO and to better implement known patterns etc.

I have quite many nested IF-statements and want to get rid of t

6条回答
  •  故里飘歌
    2021-02-01 19:53

    It's really quite a broad question to answer as it would really depend on the functionality of the if statements.

    Certainly where possible I try and replace nested if statements with a switch instead, but this is not always possible.

    Checking for parameter validity is a good approach, but look at catching it higher up in the code i.e. have the throw statements, but not the catch in the class that throws it.

提交回复
热议问题