I have several classes which extends a trait. I created a factory method that uses pattern matching in order to instantiate the relevant class.
The problem is that whenever I create a new class that extend this trait I need to add it to the factory method manually. is there an option to create the list of classes dynamically from all the classes available?
Thanks
some code examples:
current implementation :
object Test {
trait Parent
object Parent{
def apply(classType:String): Parent = classType match {
case "A" => new A
case "B" => new B
case "C" => new C
}
}
class A extends Parent
class B extends Parent
class C extends Parent
}
wanted behaviour:
object Test {
trait Parent
object Parent{
def apply(classType:String): Parent = SomeFunction(ClassType)
}
}
class A extends Parent
class B extends Parent
class C extends Parent
}