[BangPypers] Help required to design classes

Saju M sajuptpm at gmail.com
Tue Oct 9 11:25:26 CEST 2012


Hi Anand,

Sorry, I made a mistake in question
Note: constructor of class "A" and "P" doing different operations on input.

You are telling like this , right?

class BMixin:

class B(BMixin):

class Q(BMixin):

One more thing, class "B" should contain methods defined in class "A".
class "Q" should contain methods defined in class "P"  also.


So, can i do like this ???

class BMixin:

class B(BMixin, A):

class Q(BMixin, P):


Thanks,




On Tue, Oct 9, 2012 at 2:34 PM, Anand Chitipothu <anandology at gmail.com>wrote:

> On Tue, Oct 9, 2012 at 2:31 PM, Saju M <sajuptpm at gmail.com> wrote:
> > Hi,
> >
> >
> > I have two classes "A" and "B"
> >
> >
> > class A:
> >     def __init__(self, input):
> >         //do something on input
> >
> >
> >
> > class B(A):
> >     def __init__(self, input):
> >         A.__init__(self, input)
> >         //do something
> >
> >
> > Then, I want to create two new classes "P" and "Q"
> >
> >
> > class P:
> >     def __init__(self, input):
> >         //do something different on input
> >
> >
> > class Q(p):
> >     def __init__(self, input):
> >         P.__init__(self, input)
> >         //do something
> >
> >
> >
> > In class "Q", I want all the methods defined in class "B",  How do it?.
> > How redesign this class structure.
> > Note: constructor of class "A" and "B" doing different operations on
> input.
> > Note: But functionalities defined in class "B" should come in class "Q".
>
> One way do that is by writing a class BMixin and let both B and Q
> extend from BMixin. The BMixin class will have the methods that you
> would like to have in both classes.
>
> Anand
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>


More information about the BangPypers mailing list