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

Related Questions

I have some bindings that are setup as singletons. I want them to always
maybe anybody could help me out. i'm working with Data access object. i have
I have setup ability for a user to specify some settings using the in-built
I have setup mappings for a number of classes, however in some scenarios I
I have setup some simple associations in my rails app: resources :properties do resources
In a simple windows setup we have a COM singleton that runs as an
I am fairly new to Entity Framework and investigating converting some legacy data access
I have a singleton class which manages data and database handling of my application.
I have an android app that is setup to start a Java activity (call
I have a problem with this setup and I can't even view the logs.

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.