Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Parameters VS Singleton  RSS feed

Derek White
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!