[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] your opinion: singleton-pattern vs. modules vs. classes



On 3/3/08, Pete Shinners <pete@xxxxxxxxxxxx> wrote:
> I always like using a module as a container for all my singletons and
>  shared globals. Python modules already work this way, making it a
>  natural fit.
>
>  Python can build a class that is a "true" singleton. It involves
>  overriding the __new__ operator. But usually it's easier to write a
>  "GetMySingleton()" type of function that builds and remembers the class
>  of your type.

i'm not sure if i got this right: you
- use an "ordinary" class
- make an instance in a module and
- excess this instance only via the module?

maybe you can provide an example?