I would like to create a generic allowing me to reuse some functions for mutliple classes. Ideally my design would be:
class ColoredMesh[T <: Mesh] extends T
{
def Color(color:ColorRGBA) = {
val vertices = super.getVertexCount
// do something
}
}
class ColoredSphere extends ColoredMesh[Sphere]
class ColoredCylinder extends ColoredMesh[Cylinder]
However, this gives compile errors:
Error:(7, 38) class type required but T found
class ColoredMesh[T <: Mesh] extends T
Similar Java question Generic class to derive from its generic type parameter resulted in an answer deriving from a generic type parameter is not possible for technical reasons. I guess this applies for Scala as well. Is there some other common design pattern how to solve this?