avoiding if statements

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

    Yes its true that often complex conditionals can be simplified with polymorphishm. But its not useful all the time. Go read Fowler's Refactoring book to get an idea of when.

    http://www.refactoring.com/catalog/replaceConditionalWithPolymorphism.html

提交回复
热议问题