Sujet : Re: type annotation vs working code
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.pythonDate : 04. Oct 2023, 12:56:50
Autres entêtes
Organisation : Stefan Ram
Message-ID : <singletons-20231004125510@ram.dialup.fu-berlin.de>
References : 1 2 3 4 5 6 7
dn <
PythonList@DancesWithMice.info> writes:
- should the class have been called either;
class SomethingSingleton():
or a Singleton() class defined, which is then sub-classed, ie
A singleton is a single instance of a class that usually is
used "globally" in an application. Such as "root" in
import logging
root = logging.getLogger()
. So, when a singleton is needed in Python, I would follow
the model of "getLogger". You do not have to put in effort
to keep any client from creating more than one instance of
a class. Multiple instances of a class intended for singletons
might help when one is writing tests for this class.
(My above opinion was stolen from Brandon Rhodes.)