I have gone thru a couple of posts that said singleton is 'antipattern', blah,blah.
Honestly I do not believe so, but my curiosity has brought me to a simple question, whats a singleton alternative ?
At first I thought its a factory pattern...
Lets say we have a scenario:
A huge gaming application has a game engine thats accessible to all the subclasses.
Lets call it "GameEngine", now, ideally I would use a GameEngine.getInstance() synchronized method for a singleton implementation.
In the realm of the factory pattern, here is how I think sub classes will refer to it :
or would it be
wouldn't that be same as:
So, how exactly would we pass around a object globally using a factory ?
There are tons of other examples where smaller objects require access to a Main Logic / Engine / GUI object.
how then would an implementation of a Singleton alternative look like in this case ?