Should we always favor polymorphism over enums?

前端 未结 6 531
北荒
北荒 2021-01-31 18:59

After watching: The Clean Code Talks -- Inheritance, Polymorphism, & Testing

I checked my code and noticed a few switch statements can be refactored into polymorphis

6条回答
  •  一个人的身影
    2021-01-31 19:14

    "Does this mean enums are "evil" in OO-design and should be eliminated with polymorphism?"

    Usually.

    switch/enum constructs can be any of a number of polymorphic structures: State and Strategy are two common ones that come up most often.

提交回复
热议问题