Inheritance but only partly?

Tim Rowe digitig at gmail.com
Fri Oct 3 07:27:50 EDT 2008


2008/10/2 process <circularfunc at gmail.com>:
> Let's say I have a class X which has 10 methods.
>
> I want class Y to inherit 5 of them.
>
> Can I do that?

As others have said, no. What nobody seems to have said yet is why. If
Y descends from X, you are saying that Y is an X; that a Y can be used
anywhere an X can. If Y doesn't support some methods of X then it is
*not* an X, and *can't* be used anywhere an X can.

Rather than looking at workarounds, as others have, I think you need
to go back to your design and work out what's gone wrong that you
/want/ to descend Y from X. Your present design is wrong, plain and
simple. Working around it won't fix that.

-- 
Tim Rowe



More information about the Python-list mailing list