Partial 1.0 - Partial classes for Python

Michele Simionato michele.simionato at gmail.com
Thu Feb 8 07:59:17 EST 2007


On Feb 8, 1:04 pm, s... at pobox.com wrote:
>     greg> When I want to do this, usually I define the parts as ordinary,
>     greg> separate classes, and then define the main class as inheriting
>     greg> from all of them.
>
> Agreed.  Maybe it's just my feeble brain, but I find this the most
> compelling (and easy to understand) use for multiple inheritance by far.
>
> Skip

That is a common design, but I don't like it, since it becomes very
easy to get
classes with dozens of methods inherited from everywhere, a modern
incarnation
of the spaghetti-code concept. I find it much better to use
composition, i.e. to
encapsulate the various behaviors in different objects and to add them
as
attributes. In other words, instead of a flat class namespace with
hundreds
of methods, I prefer a hierarchical namespace, a class with few
attributes, which
in turns have their own attributes, and so on. In other words, nested
is better
than flatten ;)


       Michele Simionato

P.S. Of course I mean situations where the methods can be meaningfully
grouped
together, which I find is the most common case.




More information about the Python-list mailing list