0

Yes, I admit this is the same old question, but I used to apply this pattern heavily in my game engine (if it counts one) design.

I noticed in this question http://stackoverflow.com/questions/137975/what-is-so-bad-about-singletons , Jim Burger has given his answer, yes it's true that my codes are tightly coupled, but where I apply singletons are managers used in my engine, for instance, resource manager which manages all sorts of images, audios and data. I can ask for resource anywhere in my code "ResourceManager.getInstance().getImageAndCacheIt("someimage"); ", so on top of my engine, the game logic codes are coupled tightly with it.

It is common your codes? Is there a better solution?

And I used to think that some of the Classes which Android Activity uses are singletons, however after digging into the source code, I found that they are surprisingly not, they are lazily instantiated with some configuration, should I use this approach instead?

And would you be so kind as to tell me some of your engine design experiences, what subsystems do I need, do you use a visual tree or draw your elements directly line by line?

By the way, what language do you use to make 3d video games, java or c++ or something else, now I'm working on java/opengl es

Community
  • 1
  • 1
Liang Zhao
  • 135
  • 2
  • 11

1 Answers1

0

A common alternative to singletons is to use Dependency Injection.

Peter Wooster
  • 5,824
  • 1
  • 25
  • 38