title: Scala typed trait different types Implementation keeping it in Map, not working
body: <p>Is there any better design to achieve this scenario?</p>
  
  <pre><code>case class Animal()
  case class Dog() extends Animal
  case class Cow() extends Animal
  
  trait BasePropertyImpl[T &lt;: Animal] {
    def property1(animal: T): T
  
    def property2(animal: T): T
  }
  
  object DogPropertyImpl extends BasePropertyImpl[Dog] {
    def property1(animal: Dog): Dog = ???
  
    def property2(animal: Dog): Dog = ???
  }
  
  object CowPropertyImpl extends BasePropertyImpl[Cow] {
    def property1(animal: Cow): Cow = ???
  
    def property2(animal: Cow): Cow = ???
  }
  
  object AnimalImplRegistrar {
    def getRegisteredAnimals: Map[String, BasePropertyImpl[Animal]] = Map(
      "Dog" -&gt; DogPropertyImpl,
      "Cow" -&gt; CowPropertyImpl,
    )
  }
  
  object Main {
    def main(args: Array[String]): Unit = {
      val animal = AnimalImplRegistrar.getRegisteredAnimals.get("Dog").get
      aminal.property1(Dog())
    }
  }
  </code></pre>
  
  <p>Here what I am trying to achieve is deferent implementation say CowPropertyImpl, DogPropertyImpl , or some more different implementations, I am keeping it in a Map and in runtime based on user input I am retrieving the implementation from Map and calling the method of that Impl class</p>