4 ms·
I don't have much time so pardon the brevity, but I believe it's been proven that inheritance and delegation have equal expressiveness. > Often [delegation] no
by _a_a_a_ 3y ago
I don't have much time so pardon the brevity, but I believe it's been proven that inheritance and delegation have equal expressiveness.
> Often [delegation] not sufficient. You want to actually customize the implementation in some way. OOP's inheritance is ideal for this
The usual way of customising behaviour without inheritance is to pass in an object to actually implement the behaviour.
var LogToConsole = new logger(new WriteToConsole());
vs
var LogToFile = new logger(new WriteToFile());
Which customises the logger class. Trivial example but I use this a lot.
> I think this is because [inheritance is] so flexible you can easily make a mess with it, and some people have
agreed
- mike_hearn 3y agoIt's all Turing complete, so of course you can implement the same thing as protected methods by using callbacks. When I say power here I don't mean in the sense that you literally can't do it any other way, I mean it's more convenient and natural. C++/Java/Kotlin style OOP is basically about putting common design patterns into language syntax. You could do it all with C, but it's easier if the compiler does it for you. For example Kotlin has "data classes" and Java now has "records" which are in both cases classes, but they sacrifice inheritance in order to auto-generate more boilerplate for you. That's still OOP though.