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

Re: [pygame] main game object using singleton/global/static?



Daniel Jo wrote:
Either singletons or globals would work fine. Singletons are more useful when you see a need to enforce a rule that the class must be instanced only once, but if you are the only developer and can trust yourself not to do something silly, globals work just as well. I tend to use singletons because I avoid globals as a matter of principle (except in prototype programs).

In python, there's no difference because there's no real notion of "private". In fact the module system provides a nice way of ensuring that things are only instantiated once - initialize them right in the module. The import statement will only run the initialization the first time that way.

In the end I think it's a matter of preference.

--Mike