How to split up complex conditions and keep short circuit evaluation?

前端 未结 11 1869
清歌不尽
清歌不尽 2020-12-17 16:55

Sometimes conditions can become quite complex, so for readability I usually split them up and give each component a meaningful name. This defeats short-circuit evaluation ho

11条回答
  •  [愿得一人]
    2020-12-17 17:28

    The BooleanExpression type doesn't seem to be useful enough to be a class on its own outside your main class and it adds some intellectual weight to your application too. I would simply just write private methods that are named appropriately to run the checks you want. It's much simpler.

提交回复
热议问题