avoiding if statements

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

    It is quite extreme. Doing what you are suggesting would cause a lot of needless code duplication, unless the entire function was completely different, based on a single surrounding if; and if so, that if should probably have been on the other side of the method invocation.

    If-statements certainly have their place in object-orient design.

提交回复
热议问题