November 29, 2007

...Learn TDD with Codemanship

Containment & Delegation vs. Implementation Inheritence - The Proof?

And while I think about it, there might already be some insight in this Type Normalised Distance from the Main Sequence metric about why it's better to favour containment and delegation over implementation inheritence.

OK, let's consider two different designs that achieve pretty much the same code reuse. One design uses implementation inheritence, and the average Type Normalised Distance from the Main Sequence (D'T) is 0.17.

And a logically equivalent design uses a pure interface and containment/delegation to achieve the same reuse, and has D'T = 0.

For the price of three extra dependencies and one extra type in the system, we get a 100% reduction in D'T, and that may turn out to be a net profit as far as cost of change is concerned. It would certainly go some way to explaining why the anecdotes about favouring containment and delegation might be true.
Posted 4 days, 20 hours ago on November 29, 2007