I'm fairly new to Scala, and am writing an API library and trying to use only vals and immutable objects (where possible). I'm trying to decide on the right way to model the objects. Suppose there are several "Post" objects, which all share some common fields, and each adds its own specific fields:
abstract class Post(val id: Int, val name: String, ...)
case class TextPost(val id: Int, val name: String, ..., val text: String) extends Post(id, name, ...)
case class PhotoPost(val id: Int, val name: String, ..., val url: String) extends Post(id, name, ...)
This method adds a lot of repetitive declarations and boiler-plate code, especially when dealing with many Post subclasses and shared fields declare in the abstract class. The way I see it, this is caused by the use of vals which can only be initialized by the constructor. Is there a better way to create the relationships detailed here, or must I suffer this for wanting to use only immutable objects?