I have the following code:
trait Vehicle{
val speed:Int
}
case class Car(speed: Int, color: String) extends Vehicle
case class Plane(speed: Int, numberOfEngines: Int) extends Vehicle
case class Storage(vehicle: Vehicle, size:Int)
When using a trait as one of the named parameters of a case class, I loose the benefits of a case class, for example the copy method.
So if I want to update a vehicle speed like this:
val x = Storage(Car(100, "red"), 10)
x.copy(vehicle = x.vehicle.copy(speed = 30)) //this will not work.
This is obvious. The thing is it looks like the design here is bad, and that's why I ended with this problem.
Is there a better way to model this?