Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

14.13. Are Case Classes Evil?

The example in the preceding section can enrage OO purists. Shouldn’t price be a method of the superclass? Shouldn’t each subclass override it? Isn’t polymorphism better than making a switch on each type?

In many situations, this is true. If someone comes up with another kind of Item, one needs to revisit all those match clauses. In such a situation, case classes are not the right solution.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial