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 8381977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:49:13+00:00 2026-06-09T16:49:13+00:00

My program has a window where to draw and works on a model (a

  • 0

My program has a window where to draw and works on a model (a class). Many other classes (objects) at runtime will use these two. For this reason I need to keep a reference to them. Until now, I just kept two pointers as member variables in my main GUI class, but now I would like to use a better strategy. Singleton pattern seemed to be ideal, but many says that it is better not to use. Alternatives seems to be Direct Injection (which I think is not ideal for my case) or other patterns, like the Factory Pattern. But Factory pattern creates stuff and does not keep references to the created stuff, or am I wrong? Are there other patterns that could help me to have some kind of global container that keeps references to objects that many other objects will use?

  • 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-06-09T16:49:15+00:00Added an answer on June 9, 2026 at 4:49 pm

    I’m not sure you need to change how the references are kept. The main GUI class keeps track of what is created as part of the application, which is perfectly reasonable.

    Using Singleton basically means “Create some other object than the main GUI class that keeps track of which objects are created. Now instead of asking the GUI class, and object will ask the Singleton instead. If they already ask the GUI class, it fulfills the same purpose as a Singleton does.

    So, if you code looks like this:

    object.myMethod {
    <...>
      draw(mainGuiClass.textWindow, bla, bla, bla);
    

    …and textWindow is static, you are probably already using mainGuiClass as a Singleton.

    If what happens instead is that methods are invoked like this object.someMethod(mainGui.textWindow, bla, bla, bla) or your objects are created with a reference to mainGuiClass or mainGuiClass.textWindow, you are using some kind of Injection.

    Does this help?

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

Sidebar

Related Questions

I have a data model where a 'Program' has a 1-to-many relationship with 'ToDo's
I am talking about windows GUI programs. Say a program-window has a dialog box
My program has to use certain files that reside in another directory. Right now
My program has the following class definition: public sealed class Subscriber { private subscription;
The data model in my program has a number of discrete states, but I
I am working on a simple window form program. The program has a ListView.
I'm setting up a program that has three different windows. I'm just using ..
I'm porting a windows program from 32 -> 64 bit. It has a 32
My program has two threads: Main execution thread that handles user input and queues
My program has one dialog and two sockets. Both sockets are derived from CAsyncSocket,

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.