It's not that uncommon tho. You have a set of item...
# announcements
g
It's not that uncommon tho. You have a set of items that share common properties and differ by one field. The result of modeling this will be quite chatty.
🤔 1
g
Maybe in this case better to use composition rather than inheritance?
g
You mean to repeat common fields, without having them in the parent? But then you lose polymorphism and ability to process them in a generic way... I'm wondering what Scala and Haskell can say about this ADT aspect.
a
In Haskell there is no subtype polymorphism, everything is done with composition
The example you posted could be written in a different way:
Copy code
class Person(val id: Int, val name: String, val type: PersonType)

sealed class PersonType {
    class Developer(/*custom parameters */): PersonType()
    class Painter(/*custom parameters */): PersonType()
}
1