On Apr 22, 10:36 am, George Sakkis <[EMAIL PROTECTED]> wrote:
> On Apr 22, 10:22 am, Carl Banks <[EMAIL PROTECTED]> 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
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to