OOP: method overriding works in mysterious ways?

John M. Gabriele john_sips_teaz at yahooz.com
Mon Jan 2 18:02:16 EST 2006


Scott David Daniels wrote:
> Dustan wrote:
> 
>> .... From my experience, the methods are passed
>> down, not referred to from the parent. That is, Parent does have its
>> own critique method, not a reference to Grand_parent.critique(). 
> 
> This is typical of static binding as (for example) seen in C++.  If you
> think of dynamically bound systems like Smalltalk, Ruby, and Python, the
> more unusual case is wanting to go up the hierarchy (where you use super
> to get the behavior you are apparently expecting).  Think of Python's
> method dispatch as always being "virtual".

Ah. Not only that, but the other ingredient (I think) is to keep in mind 
that you're always calling instance methods via the self object -- and 
that self object is always the same object regardless of how far up the 
inheritance tree you go with those method calls, right?

> --Scott David Daniels
> scott.daniels at acm.org

---J
-- 
(remove zeez if demunging email address)



More information about the Python-list mailing list