Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7503451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:13:36+00:00 2026-05-29T21:13:36+00:00

I have some Classes like Clipboard or ProcessRegister that I only want to run

  • 0

I have some Classes like Clipboard or ProcessRegister that I only want to run once in my Project, so only one instance.

My Question in now: How do I distribute those instances best in my Project.

ATM both are singleton and object they use the get an instance over the getInstance().

Another Idea of mine is to create a class Project, that has some static methods like getProjectClipboard()or getProcessRegister()that return the instances.

What is the best way to distribute them? Are there any patterns for that?

Greetings Dennis

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:13:40+00:00Added an answer on May 29, 2026 at 9:13 pm

    There are mainly two patterns that can be used: the service locator, and dependency injection. The service locator pattern is probably the one you are referring to, where everywhere you look for a reference for these objects you explicitly retrieve it from a central location, which for simple java applications is usually a bunch of static methods. this is OK, and I don’t think there is an overall better approach here, just make sure that you have only one static method for each singleton, and that you call it always.

    Then a few years ago, a shift of mentality became mainstream, dependency injection, and its more popular framework… Spring, with this paradigm, in each place you need to access this singletons, you don’t specify where they are, but your object get the correct references injected…

    I would recommend you to look into dependency injection… and probably Spring, as it is the mainstream solution for it… I think that giving you more insgight into Spring is out of the scope of the question, but there is A LOT of documentation in Internet if you search for Spring tutorials or something similar…

    Basically what you would do is create as spring beans each of your singletons, and then have spring injecting them into your objects… The caveat to this approach is that all of your objects have to be built by Spring, but in practice it doesn’t suppose any disadvantage, it will actually make your life easier in terms of testings, maintenance…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

got a question regarding serializing classes that I've defined. I have some classes like
I have authored some custom classes that I would like to create using XAML:
I have an interface that defines some methods I would like certain classes to
I have some classes in C++ that I would like to expose to Lua.
Say that i have some classes like this example. class A { int k,
I have some classes that look like this: MODEL public abstract class BaseEntity<O extends
I have some classes that i'd like chain methods of to provide a fluent
I have some simple ruby classes that I want to use with rails (they
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {
I have some classes layed out like this class A { public virtual void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.