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 Parameters VS Singleton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Parameters VS Singleton" Watch "Parameters VS Singleton" New topic
Author

Parameters VS Singleton

Derek White
Greenhorn

Joined: Jul 24, 2008
Posts: 14
Hello everyone

I've been writing some applications in Java lately and now face a slight conundrum regarding parameterized constructors and singleton patterns.

- The two classes I refer to, UpdateManager and Settings, reside in the same package.
- I need to access what should be a single, program-wide instance of Settings from UpdateManager
- Settings will be modified from some dialog outside of the package
- UpdateManager will be used from some frame outside of the package

I do not understand which programming style would be better in this case. Should I pass in a Settings object as an argument in UpdateManager's constructor even though there should always be only instance of Settings at any given time?

What are the pros and cons of parameterization? Singleton patterns?

Is it just preference?

It would be really helpful if someone could explain some situation where either style might lead to an unseen problem.

Thanks a lot!
Derek White
Greenhorn

Joined: Jul 24, 2008
Posts: 14
I actually found some really great articles:

http://misko.hevery.com/2008/07/08/how-to-think-about-the-new-operator/
http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/
http://tech.puredanger.com/2007/07/03/pattern-hate-singleton/
http://www.codingwithoutcomments.com/ (top post)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parameters VS Singleton