What are the disadvantages to declaring Scala case classes?

后端 未结 5 2046

If you\'re writing code that\'s using lots of beautiful, immutable data structures, case classes appear to be a godsend, giving you all of the following for free with just o

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 06:04

    I think the TDD principle apply here: do not over-design. When you declare something to be a case class, you are declaring a lot of functionality. That will decrease the flexibility you have in changing the class in the future.

    For example, a case class has an equals method over the constructor parameters. You may not care about that when you first write your class, but, latter, may decide you want equality to ignore some of these parameters, or do something a bit different. However, client code may be written in the mean time that depends on case class equality.

提交回复
热议问题