Why a class when there will only be one instance?

Jorge Godoy godoy at ieee.org
Tue May 25 20:50:10 EDT 2004


On Ter 25 Mai 2004 21:43, SeeBelow at SeeBelow.Nut wrote:

> I see the value of a class when two or more instances will be created,
> but Python programmers regularly use a class when there will only be one
> instance.
> What is the benefit of this?  It has a disadvantage of a whole lot of
> "self."
> being required everywhere, making the code less readable.  Also, since a
> strength of Python is rapid application development, it slows one down
> to have to put in all those self.'s.  The code seems much cleaner to me
> without classes that have only one instance.  Oh, also, all the methods
> of this class will have to have the instance name prepended to them.
> 
> I would appreciate it if someone could explain the advantages of doing
> this, or at least the sociological reasons why it occurs.

How can you guarantee that such a code will never ever be used again,
anywhere?

It's easier to allow for code reuse from the beginning, IMHO.

-- 
Godoy.      <godoy at ieee.org>



More information about the Python-list mailing list