File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Parameters VS Singleton" Watch "Parameters VS Singleton" New topic

Parameters VS Singleton

Derek White

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

Joined: Jul 24, 2008
Posts: 14
I actually found some really great articles: (top post)
I agree. Here's the link:
subject: Parameters VS Singleton
It's not a secret anymore!