Multiple constructors

Nick Coghlan ncoghlan at iinet.net.au
Mon Feb 7 07:54:17 EST 2005


Caleb Hattingh wrote:
> Though Alex indicated differently earlier, I intend to always use an 
> "if"  statment inside one constructor to initialise any class in the 
> situation  where the arguments may be different in number and type.  I 
> don't have the  years of experience that Alex has, however, so I may end 
> up regretting it  but right now, it seems to me to be the clearest 
> approach in this  situation.

It varies, and often depends on the *promises* a class can make regarding a set 
of inputs. If you can get a similar effect from a bunch of different types of 
inputs, then putting the functionality all in one method is reasonable.

On the other hand, if there is a significant semantic difference associated with 
certain inputs, but you *can* do something useful with them, then a separate 
method may be called for.

The above applies to both ordinary methods and constructors. The builtins and 
the standard library offer many examples of both situations.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list