2 ms·
One way I think of it is that inheritance is like trying to model a complete solution all at once, doing the design up front and in a top-down manner. Everythin
by davnicwil 8y ago
One way I think of it is that inheritance is like trying to model a complete solution all at once, doing the design up front and in a top-down manner. Everything's deeply tied together and more difficult to change later when you realise the design was wrong and when you need to add more stuff. Often, making a change in one place is like pulling a brick from the bottom of a pile - everything else is affected. It's very inflexible.
Composition is a bit more like building a solution as you go from the bottom up - you solve the sub problems one at a time and then just combine these solutions together iteratively to solve the larger problem. When things change, it's quite easy to change these small solutions, throw some away, build new ones, and recombine them. It's a much more abstract, much more flexible way to piece together your overall solution.