Inheritance but only partly?

Aaron "Castironpi" Brady castironpi at gmail.com
Thu Oct 2 22:45:22 CEST 2008


On Oct 2, 3:16 pm, process <circularf... at gmail.com> wrote:
> 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? Can I do something along the lines of super(Y, exclude
> method 3 4 7 9 10) ?

That implies that the 5 you do include don't rely on or call the 5 you
don't.  Otherwise you have to inherit them.  Then you can refactor
them into:

class X5YouDo: ...
class X5YouDont: ...
class X( X5YouDo, X5YouDont ): ...
class Y( X5YouDo ): ...

If you're looking for restricted visibility, Python does not have it.
It's just handcuffs, and makes things you can't do.

After all, nothing would stop you user from calling:

y= Y()
X5YouDont.DontInheritMe( y, args )

to get at the uninherited methods.



More information about the Python-list mailing list