Should we always favor polymorphism over enums?

前端 未结 6 521
北荒
北荒 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:26

    class Sunday extends DayOfWeek {}
    class Monday extends DayOfWeek {}
    class Tuesday extends DayOfWeek {}
    class Wednesday extends DayOfWeek {}
    class Thursday extends DayOfWeek {}
    class Friday extends DayOfWeek {}
    class Saturday extends DayOfWeek {}
    

    Enums are fine.

提交回复
热议问题