DEV Community

Discussion on: Why composition is superior to inheritance as a way of sharing code

Collapse
 
danieldubovski profile image
Daniel Dubovski

There is no one true purpose to a design principal, as things evolved a lot along the way.
Inheritance is used in a lot of languages , with a lot of specific features, all designed for different use cases (of course some of them overlap).
That being said the theory and practice of Inheritance vary, and it is often used to share functionality, because it's relatively ease and clean to use.

Collapse
 
jluisestrada profile image
JLuis Estrada

Obviously you can use inheritance the way you want. Is not restrictive at all other than a few rules that change from language to language.

But overall, that's the key feature of inheritance: share characteristics among a descendants in order to create a cohesive domain.

Thread Thread
 
danieldubovski profile image
Daniel Dubovski

I think the problem here is the terms we use.

I would love to see a reference to back you up. programming is prone to opinionated discussion, so some background to the opinion you hold might be helpful.

If by characteristics you mean properties, then I disagree, as a characteristic can also be a function (or a capability).

Anyway, I might be wrong, but check these out:

www2.latech.edu/~box/ase/tp/Per%20...

en.wikipedia.org/wiki/Object-orien...

esug.org/data/Old/ibm/tutorial/CHA...