Re:Composition over Configuration
by shock on Wednesday April 10, 2019 @02:01AM
(#19622258)
> But is there a fundamental benefit of composition over inheritance in ever circumstance?
I don't have much time now, but a fundamental difference is that inheritance happens at compile time (it's rare/nonexistent that you can change the class hierarchy at runtime) while composition happens at runtime – this means that with composition one can change the behavior of a class at runtime by inserting in a field a different implementation of an interface, for example.
I don't have much time now, but a fundamental difference is that inheritance happens at compile time (it's rare/nonexistent that you can change the class hierarchy at runtime) while composition happens at runtime – this means that with composition one can change the behavior of a class at runtime by inserting in a field a different implementation of an interface, for example.