When is a subclass not right?

Fredrik Lundh fredrik at pythonware.com
Thu Aug 24 15:44:47 EDT 2006


please don't hit reply to arbitrary messages when you're posting new
messages; it messes up the message threading.

Chaz Ginger wrote:

> I was writing some code that used someone else class as a subclass. He 
> wrote me to tell me that using his class as a subclass was incorrect. I 
> am wondering under what conditions, if ever, does a class using a 
> subclass not work.

your terminology is confused: if you inherit from another class, *your* 
class is the subclass, while the class you inherit from is known as a 
"base class" or "super class".

a subclass will share the instance namespace with the base class, which 
means, among other things, that you may accidentally override internal 
attributes and methods, and thus break the base class.

and even if it appears to work now, it may break when you upgrade the 
base class.  or when you end up in a code path that you haven't tested 
before.

</F>




More information about the Python-list mailing list