4 ms·
I like composition because it's easier to create small testable component contracts. You don't need testability or 'greenfielding' for this. 'Design by contrac
by pvg 8y ago
I like composition because it's easier to create small testable component contracts.
You don't need testability or 'greenfielding' for this. 'Design by contract', as you mention, is a useful way to think about this, without attaching value judgments to composition or inheritance. Inheritance is a much stronger and therefore burdensome contract. It's much less likely bits of your model can really adhere to it. The advice to lean towards composition is a function of that - few models can meet that high bar.
- squirrelicus 8y agoRight. Inheritance implies contracts that include behavior, composition implies contracts that don't. I talk of greenfielding because it's rare that the inheritance alone holds a codebase back so much that it needs to be rewritten. But code I originate is always composition based