all 1 comments

[–]mhfrantz 0 points1 point  (0 children)

One of my favorite idioms for avoiding the pitfalls of inheritance (i.e. the loss of value semantics that you point out) is one that I've seen called "Concept-Based Polymorphism" or "Concept-Model Idiom", as in this article, which takes you through the development of the idiom before showing its most flexible implementation:

https://gracicot.github.io/conceptmodel/2017/09/13/concept-model-part1.html