Remove multiple inheritance in Python 3000

Carl Banks pavlovevidence at gmail.com
Tue Apr 22 10:55:03 EDT 2008


On Apr 22, 10:36 am, George Sakkis <george.sak... at gmail.com> wrote:
> On Apr 22, 10:22 am, Carl Banks <pavlovevide... at gmail.com> wrote:
>
> > Java (for example) allows a class to share behavior with only one
> > other class, and that *severely* limits the opportunities to minimize
> > redundancy.
>
> Not really; composition is usually a better way to share functionality
> and reduce redundancy than inheritance.

I should have known this was coming.  I disagree: inheritance is a
much better way to share behavior.  Use inheritance by default,
composition if you have to.  (Or composition when it actually reflects
a composition relationship, and not mere behavior sharing.)

With composition you're burdening the user with having to learn the
shared relationships that ought to be implementation details of the
class.  E.g.,

obj.action_style.perform_action()

With inheritance, the user doesn't have to worry about these
relationships.

obj.perform_action()

It's better to isolate complexity (which inheritance does) than to
spread it out (which composition does).


Carl Banks



More information about the Python-list mailing list