Python Design Patterns - composition vs. inheritance

Neil Cerutti horpner at
Sat Nov 17 16:57:14 CET 2007

On 2007-11-17, Odalrick <odalrick at> wrote:
>> But that breaks expectations: a user doesn't expect
>> set_width() to affect the height.
> I can't speak for everyone but I certainly expect setting the
> width of a Square to change it's height. In fact, that would
> probably be the reason I used a Square rather than a Rectangle
> in the first place.

Some of the dissonance is from assuming that rectangles can
mutate themselves. I've never seen one do that! ;) The rest of
the dissonance is caused by strong typing. A rectangle with equal
width and height is still a rectangle, in a strongly typed

Neil cerutti

More information about the Python-list mailing list