inheritance

Ian Kelly ian.g.kelly at gmail.com
Thu Apr 5 14:11:16 EDT 2012


On Thu, Apr 5, 2012 at 11:50 AM, Yagnesh Raghava Yakkala
<yagnesh at live.com> wrote:
>>>you will have
>>> to pass the instance in explicitly as the self argument.  For example:
>>
>>> B.foo(x)  # calls B.foo directly with instance x
>
> After follow up, I see one problem(can i say that?) with this. With python
> overwriting methods of super class(es), one need to keep track of all the
> methods ever defined in the super class(es). do everybody do a check before
> writing a new method for existing method with the same name.?

That syntax is for extraordinary cases where you know that you always
want a specific version of the method from a specific class in the
inheritance hierarchy to be called.  Normally, you would just do
"x.foo()" and allow the type of x to determine the exact method that
is called.  As long as you design your classes with encapsulation and
the Liskov substitution principle in mind, it should not matter to you
whether "x.foo()" results in calling B.foo or C.foo is called, because
the end result will be the same, with any variations appropriate to
the actual type of x.



More information about the Python-list mailing list