Considering the following code :
sealed trait Foo {
def name: String
}
case object FooA extends Foo {
override val name: String = "a"
}
case object FooB extends Foo {
override val name: String = "b"
}
object Foo {
def fromString(name: String): Foo = {
name match {
case FooA.name => FooA
case FooB.name => FooB
}
}
Can I refactor the fromString() method to avoid having a case per case object instance ? Some more generic code able to enumerate through all Foo instances ?
In my real version, I start to have a lot of case object, and the wall of case bla.name => bla
is boring me ^^
Thanks :)