Maybe what you’re really looking for is a component-based architecture? Here’s just one example: Component System - Same Face, New Engine — Starmancer
You’ve probably heard “composition over inheritance”. In the same vein, another phrase I would add is: “don’t inherit in order to gain implementation”.
For example, let’s say you’re implementing collections. It would be a mistake to implement a Map, then while you go on to implement a List, subclass your list from map. List is not “is a” map. Instead we use composition and List “has a” map. (Not that you’d want to use Map in the first place but I’ve seen this specific mistake with collections IRL).
Yes you can create a super type
Animal with a
height property. That may be correct if every animal has a height–which is probably correct. Composition does not break encapsulation, it enables more encapsulation by hiding details within the individual components.
Some meta notes:
It’s possible that we’re still in the XY problem–which is why I suspect you may want to consider a different approach. I’d guess 2/3 of requests for new Kotlin features on this forum fall into the trap of asking for a solution that doesn’t fit.
Another example of an XY problem would be asking for a “componentN” for all data class members when the real need is a flexible data structure type. In that example, the requester is trying to make data classes be that flexible data structure type, which is like asking how to drive a screw with a hammer.
It’s easy to fall into the trap of asking for multiple inheritance and misusing it. It’s pretty normal for develops to have a “multiple inheritance makes sense!” phase at some point when learning OOP
It’s great that you’re heading in the direction of composition, that is the right way to go. Make sure you’re continue to evaluate if the solution you’re trying to implement might not fit–keep going back to “why am I trying to do X?”
I’d recommend equipping yourself with all of the standard patterns, an architectures or two, reading Clean Code by Robert Martin, and copying the designs from existing software. That way you’re less likely to fall into seeking answers for the wrong solutions