If I have several subclasses of a particular abstract class.
abstract class CylindricalProjection(val cut:Double) extends Projection {...}
class PetersProjection(verticalCut:Double= -168.0) extends CylindricalProjection(verticalCut = verticalCut) { ... }
class MercatorProjection(verticalCut:Double= 180.0) extends CylindricalProjection(verticalCut = verticalCut) { ... }
class SimpleProjection(verticalCut:Double= -168.0) extends CylindricalProjection(verticalCut = verticalCut) { ... }
Is there a way for me to instantiate the classes indirectly in a loop, particularly in a test case?
For example, in the file where I define the classes, I’d like to have an object which contains the sequence of classes.
object Foo {
val projectionClasses = Seq(SimpleProjection, MercatorProjection, PetersProjection)
}
And then in several different test cases do something like the following. Of course this syntax does not work. Just wondering the correct way to do this.
for{ c <- Foo.projectionClasses
cut <- Seq(-180.0 -120.0, 0.0, 45.0)
em = EarthMap()(projection = new c(verticalCut= cut))
} assert( ... something about em ...)