That’s a handegg.

]]>This is a defence of my thesis :). You can use the *concept* square everywhere you can use the *concept* rectangle, because a square *is* a rectangle with additional constraints. You cannot use the *type* square everywhere you can use the *type* rectangle, because a square has stricter invariants than a rectangle. The fact that this is confusing is an argument against trying to use inheritance to model both of these relationships.

`"you can’t use a Square anywhere you would use a Rectangle"`

because you “can”, but

`"you shouldn’t use a Square anywhere you can use a Rectangle"`

because it (probably) won’t give you the result you want.

]]>Myclass::SizeOfAffectedArea( Rectangle &r );

If you pass a square in as the argument to receive the affected area, either its height or its width will be wrong, since the method will attempt to update them separately.

Oh, and Graham, a football is an ellipsoid.

]]>“You can use a rectangle everywhere you can use a square, but you cannot use a square everywhere you can use a rectangle.”

It should read like:

“You cannot use a rectangle everywhere you can use a square (since the square is a special case of a rectangle [need all 4 sides to be of same length]), but you can use a square everywhere you can use a rectangle (since rectangles don’t have restrictions about side length, every square IS a rectangle anyway).”

]]>However, I find one of the key problems with inheritance is trying to apply it to entire entities — it breaks down for non-trivial entities having multiple interactions, since the API & code reuse needs of each interaction may be different.

The solution I bring to bear is to factor interactions separately, designing their interfaces on a behavioral basis. This seems highly effective in allowing robust substitution, code reuse where warranted, and independent variation of different entity interactions.

An article & commentary on this approach:

– http://literatejava.com/oo-design/oo-design-is-more-about-doing-than-being/

– http://literatejava.com/java-language/why-inheritance-never-made-any-sense/

I suppose that 1) and 3) are implemented via traditional inheritance and we can achieve 2) by using modules.

Am i right ?

Thank you. ]]>