3 ms·
My personal preference for composition over inheritance is that it forces callers to call the owned-object’s methods directly rather than automatically through
by tyleo 11mo ago
My personal preference for composition over inheritance is that it forces callers to call the owned-object’s methods directly rather than automatically through inheritance.
There is more typing/boilerplate but when you read the class file you get a full picture of what’s happening rather than some parts happening automatically in a different file.
I like to say that code should be written with a reader bias: the singular writer should do more work if it makes the class more obvious for the multitude of readers. I feel like composition is a good example of that.
- DarkNova6 11mo agoThe way I like yo phrase it: concretion over indirection.
- mekoka 11mo agoI call it "read-optimized code". Inheritance is biased toward conservative writing. Once your mind becomes so enmeshed with the code base that you can no longer fathom a future where you might fall out of sync with it, inheritance becomes extremely appealing. It's all in your head! You pull the Razzle parent, sprinkle a bit of Dazzle mixin, everything is alchemized into a Fizzle class and abracadabra. Meanwhile newbies in the team have their eyes welling up from having to deal with your declarative mess.
- tyleo 11mo agoThat’s a great term and I’ll probably use it instead of mine. Thanks!