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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:51:56+00:00 2026-06-16T14:51:56+00:00

Despite the many threads on that topic, I am still unclear as to when

  • 0

Despite the many threads on that topic, I am still unclear as to when to choose which approach.
I am hoping that by discussing a specific example, I will finally “get it.”

Note: My language here is Cocoa though the general issue is not language-specific.

I have a class TaskQueue that I want to use to:

  • access from anywhere in my code in order to add or remove scheduled tasks
  • process automatically the scheduled tasks at regular intervals

When TaskQueue is first used, I want TaskQueue to initiate a thread that will then wake up at regular intervals to process the tasks.

Obviously, I will need at a minimum two variables:

  • an array to store the tasks
  • an instance of the thread processing the tasks

Since I only want one queue of tasks and one thread to process these tasks, I have two choices:

  1. Make TaskQueue a singleton class (using for example CWL_DECLARE_SINGLETON_FOR_CLASS_WITH_ACCESSOR as described in http://www.cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html, which I believe I will have to modify the CWLSynthesizeSingleton.h file to start the thread at init time.)

  2. Have the array of tasks and the thread instance both be static (following the approach suggested here: How do I declare class-level properties in Objective-C?)

Is there clearly one approach that’s better than the other one in this specific case? If so, why?

  • 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-16T14:51:57+00:00Added an answer on June 16, 2026 at 2:51 pm

    The main differences are simple things like:

    • with a singleton you can pass around the object for delegates and callbacks
    • with a singleton you can implement interfaces and derive it
    • with a singleton you can use a factory pattern to build up your instance

    If you don’t need any of them, as with global functionality that must be accessed all around your code then you can go with static methods.

    I personally prefer using static methods unless I have an explicit reason to use a singleton instance (such as having a common interface but different implementations).

    Mind the fact that refactoring static methods to a singleton instance is quite a straightforward process so if you ever find the need for the latter you will refactor it easily (then you have the C preprocessor, a single #define would be almost enough).

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

Sidebar

Related Questions

I have some issue with too many Threads unfinished. I think that queue command
Despite the many stories that I've heard about people having problems installing numpy, scipy,
Despite reading many articles (some on this board) I am still scratching my head
Despite the accepted answer, I'm still hoping for a more detailed one, with examples.
despite many tries I can't get the result that I would like to see
Many array methods return a single index despite the fact that the array is
Despite substantial research and many posts that seem to indicate this isn't too tough,
There have been many threads started over the confusion in the way that Math.Round
Despite I have been using MVC in PHP many times, I found out that
I encountered an error. Despite declaring the variables (failturetext and userName) errors still appear.

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.