Unintended inheritance

Kay Schluehr kay.schluehr at gmx.net
Mon Feb 20 13:44:43 EST 2006


The problem of unintended inheritance is typical for OO frameworks and
can be explained as follows. Given a class Foo implemented by Alice and
a derived class Bar of Foo implemented by Bob. Bar implements a method
f. In a later version of Foo Alice also implements a method f. The f of
Bar overrides the f of Foo unintentionally. If an instance bar of Bar
will be created and some method g of Foo calls f it is the wrong f,
namely the one of bar will be called.

To prevent unintended inheritance C# introduced a relatively complex
contract semantics using three modifiers virtual, override and new. Is
this issue serious for Python programmers, in particular for those
working in larger projects ( Twisted, Zope ... ) or is it not? If not,
why not?

Kay




More information about the Python-list mailing list