Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
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.