Hacker News new | ask | show | jobs
by AstralStorm 3126 days ago
Ahh the fabled Multiton pattern. The similar ones are:

Making the singletons in shared objects, each one gets it's own. Adding a destroyInstance method.

1 comments

I've actually used a destroyInstance method, for testing. But if you do that, first, nobody can hang on to the pointer they get from getInstance, ever, anywhere in the entire code base. And second, the instance has to be a pointer (so that destroyInstance can delete it), and destroyInstance has to NULL the pointer. Then getInstance has to create a new instance if the pointer is NULL.

It can be done, but if anybody ever calls destroyInstance in production code, well, I question their approach...