Singleton : Fields vs Globals

BlitzMax Forums/BlitzMax Programming/Singleton : Fields vs Globals

I still prefer how I do it, I can just see how yours works.

I would have a problem with your code should the Singleton be for example the setup class of a 3D engine, where its parameters are set up at the start. If modules are used, and the instance doesn't exist, then there's a problem still, so it would be better to error out on Getinstance() when there is no instance, and to error out on a multiple create().

For example: If someone tried to make two instances of our Tgame class, it should error out because it doesn't make sense that it happened twice. You cant put the create() code in Getinstance() because it needs setting up with parameters.

Now, if you handle it by creating the instance and setting it up via other functions, fair enough. if all the create method is doing is creating a reference, then off you go, but somewhere, the parameters will need setting before some other code craps out without a meaningful message. :-)