[BangPypers] Help required to design classes

Anand Chitipothu anandology at gmail.com
Tue Oct 9 11:04:25 CEST 2012


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


More information about the BangPypers mailing list