File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Whats a Singleton alternative ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Whats a Singleton alternative ?" Watch "Whats a Singleton alternative ?" New topic
Author

Whats a Singleton alternative ?

salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 917

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 ?

My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 917

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.
 
Don't get me started about those stupid light bulbs.
 
subject: Whats a Singleton alternative ?
 
Similar Threads
Purpose of hiding default constructor
Patterns: Abstract Factory Vs Factory Method
Singleton Factory Object
Factory pattern question
Factory Vs Abstract Factory Pattern