Inheritance but only partly?

Michele Simionato michele.simionato at gmail.com
Fri Oct 3 06:32:52 EDT 2008


On Oct 2, 10: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) ?

Don't use inheritance, use delegation or just copy the methods you
need:

class A(object):
  def meth_a(self):
     pass

class B(object):
   meth_a = A.meth_a.im_func


IMO, if you have methods that you want to use in different classes,
this is hint that
you are in need of generic functions. See this blog post for an
example:

http://www.artima.com/weblogs/viewpost.jsp?thread=237764



More information about the Python-list mailing list