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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:12:12+00:00 2026-05-16T01:12:12+00:00

The setup: I have a singleton data access manager object, call it Manager. I

  • 0

The setup: I have a singleton data access manager object, call it Manager. I also have some view controllers, call them Apples and Oranges. Both Apples and Oranges use Manager for some shared data model/access functionality.

I would like Manager to call either of them back in certain cases according to something like this:

if (someCondition)
    [self.applesDelegate callSomething];
else if (otherCondition)
    [self.orangesDelegate callSomething];

I see three ways of implementing this, none of which I am happy with.

1) do exactly as I did above, give Manager some properties like applesDelegate and orangesDelegate, and have relevant view controllers register themselves for that. But that would be bad because Manager would have domain knowledge, and I don’t want to have that. Manager shouldn’t know anything about Apple or Orange objects.

2) have a dynamic delegates map. Manager would have some NSMutableDictionary for delegates, and Apples and Oranges would do something like

[manager.delegateMap setObject:self forKey:@"applesDelegate"];

And Manager, when it would need to call the delegates, would do something like

if (someCondition) {
    [[delegatemap objectForKey:@"applesDelegate"] callSomeMethod];
}

This sounds workable but strange. And I’m not sure how it would work with the common dealloc requirement of setting the delegate to nil when you don’t have a delegate property but this kind of indirection.

3) give up on the idea of delegates altogether and use notifications instead. Manager would just generate notifications and Apples and Oranges would listen to those. This loses a lot of compile-time checks though, this is why I’m still thinking about delegates that have a bit tighter coupling.

Which of the three would you recommend here? Or perhaps something different?

  • 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-16T01:12:13+00:00Added an answer on May 16, 2026 at 1:12 am

    In some cases a chain-of-responsibility pattern is useful. Each delegate is able to determine whether it can do the task. So it just

           if ( ! apple.doItIfYouCan(condition, methodName) )
           else ( orange.doItIfYouCan(condition, methodName)
    

    I rarely feel comfortable with this diffusion of responsibility across the delegates.

    So I would normally look for something like your option 2. In effect you’re building a dispatch table. It at all possible I would try to recast the conditions into something that can be looked-up in a table. So in effect we take some information and get back an object and a method

            whatToDo = lookup(condition definition)
    
            whatToDo[who].what
    

    (apologies for the lack of syntax, I don’t speak your language, I’m hoping that the concepts translate – I could do this in JavaScript, or with function pointers in C, or reflection in Java.)

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

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is not pretty but it works: rm -R $(ls… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer Yes. Override the base1 and base2 methods in Derived to… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer No, you can't. Unfortunately, UIEvent doesn't expose any public way… May 16, 2026 at 12:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs
I have a navigation controller with a table view. In most tutorials I've read
I have setup unity in my project and it is working for objects that
I have setup a custom managed property in MOSS and mapped it to a
I have setup my site with 5 pages which are my menu options. When
I have a Setup project (MSI) in VS2008 which installs my project. Within the
I am building an Inno Setup script and have libraries that need to be
I'm implementing a singleton class as follows: static Singleton* _singletonInstance; @implementation Singleton +(void)initialize {
I have a somewhat simple Client/Server solution running over C# remoting (System.Runtime.Remoting). The MarshalByRef
So .... There are obviously many questions that all have been asked about Singletons,

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.