Stylistic question about inheritance

Steve Holden steve at holdenweb.com
Fri Apr 1 01:59:23 EST 2005


Andrew Koenig wrote:
> ""Martin v. Löwis"" <martin at v.loewis.de> wrote in message 
> news:424C5B09.9090006 at v.loewis.de...
> 
> 
>>You would normally try to avoid type queries, and rely on virtual
>>methods instead, if possible.
> 
> 
> Of course.
> 
> 
>>It seems likely for the application
>>that code can be shared across different subclasses, for example,
>>you might be able to define
>>
>>def Expr:
>>  def __str__(self):
>>    return '%s(%s)' % (self.__class__.__name__,
>>                       ", ".join(map(str, self.operands()))
>>
>>requiring you only to implement .operands() in the subclasses.
> 
> 
> Indeed.
> 
> 
>>If you can anticipate such common code, it is easier to add
>>a base class right away. If you cannot think of a specific
>>use case, there is little point in having a common base class.
> 
> 
> So, for example, you don't think it's worth including the base class as a 
> way of indicating future intent?
> 
> 
The obvious XP response to the question is "You aren't going to need 
it". If you already have the intent then basically you appear to be 
saying "I  *am* going to need it".

Since you say that almost as an integral feature of the specification 
I'm not sure I understand why you asked the question in the first place 
- unless it's really an anthropological inquiry.

regards
  Steve
-- 
Steve Holden        +1 703 861 4237  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/




More information about the Python-list mailing list