When is a subclass not right?

Chaz Ginger cginboston at hotmail.com
Thu Aug 24 15:56:10 EDT 2006


Fredrik Lundh wrote:
> 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>
> 
Sorry for the threading screw up. I thought I had just hit the write button.

I understand when my class overrides the super class. But that would 
just be "normal" class related things. I was wondering if there was 
something more subtle I am missing in Python class handling.

Chaz



More information about the Python-list mailing list