r/node • u/Terri-InstBrew • Sep 21 '15
Composition over Inheritance
https://medium.com/humans-create-software/composition-over-inheritance-cb6f880702051
1
0
u/I_Pork_Saucy_Ladies Sep 23 '15
Very, very nice explanation of the difference between the two. I completely agree.
But the really big problem with inheritance is that you’re encouraged to predict the future. Inheritance encourages you to build this taxonomy of objects very early on in your project, and you are most likely going to make design mistakes doing that, because humans cannot predict the future (even though it feels like we can), and getting out of these inheritiance taxonomies is a lot harder than getting out of them.
Oh man, I wish people would think more about this in general when developing...
"Well, do we really need a surrogate key for this table? Nah, let's just use a natural key - I mean, how would a social security number ever change? Better save the 3 seconds it takes to create that 'id' column."
Sometimes I wish I could stab people in the face retroactively.
3
u/dukerutledge Sep 21 '15 edited Sep 22 '15
This is why type classes and protocols are the bomb. They give us the added bonus of speaking about a shared interface, but not needing the exact same behavior. We can share behavior when needed, but tweak behavior for specific use cases. I'm looking forward to efficient type classes/protocols with the introduction of Symbols:
(Edit: for symbol kerfuffle)