File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Whats a Singleton alternative ?

 
salvin francis
Bartender
Pie
Posts: 1230
10
Eclipse IDE Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
salvin francis
Bartender
Pie
Posts: 1230
10
Eclipse IDE Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a side note, though I do not find singleton to be an anti-pattern, I do believe that using singleton just for the heck of storing variables that are globally accessible is a bad idea.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic