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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:24:29+00:00 2026-06-13T14:24:29+00:00

I am relatively new to Objective C, and have an architecture question regarding creating

  • 0

I am relatively new to Objective C, and have an architecture question regarding creating custom delegates around existing delegates. It’s probably best described in pseudocode. Apologies for the length, I couldn’t determine how to make it more succinct.

Overall desired architecture summary

I have a class in some library that makes a call to a web service, which takes a delegate for callbacks when the web service returns asynchronously. This low-level library is wrapped in a facade (a singleton) to shield clients from knowledge of it, and the facade methods can take a delegate that effectively wraps the low-level library’s delegates, so clients can assign themselves as delegates when the facade (itself a delegate) gets data back from web service calls).

In other words, client instance A calls the facade [f makeCallWithDelegate:self], and the facade hides its internal workings so A only has to implement the facade’s delegate’s protocol.

Pseudocode

The low level class:

// The low-level class that calls a web service
// LowLevelClass.h
@protocol LowLevelClassDelegate
- (void)success:(LowLevelClass*) c;
@end

@interface LowLevelClass
- (void)makeAsynchronousCallWithDelegate:(id <LowLevelClassDelegate>) d;
@end

// LowLevelClass.m omitted

The facade wrapping the low-level class. The issue is noted in the makeCallWithDelegate selector, and in the success delegate callback:

// partial Facade.h
@protocol FacadeDelegate
- (void)success;
@end

@interface Facade <LowLevelClassDelegate>  // the facade handles the delegate calls of the LowLevelClass
...
- (void)makeCallWithDelegate:(id <FacadeDelegate>) d;
...
@end


// Facade.m (pseudocode)
@implementation Facade

- (void)makeCallWithDelegate:(id <FacadeDelegate>) the_delegate {
  LowLevelClass * llc = ... // get instance
  [llc makeAsynchronousCallWithDelegate:self];  // delegate to self, catch events
  // Issue: have to somehow pass the_delegate to the "success" method below,
  // or have it available
}

// LowLevelClassDelegate implementation, hands result to the FacadeDelegate 
- (void)success:(LowLevelClass*) c {
  // Issue: need the_delegate to get down here somehow, or be reachable.
  [the_delegate success]
}

@end

The client:

// Client.m fragment, client implements the FacadeDelegate protocol
...
- (void)makeFacadeGetData {
  [facade makeCallWithDelegate:self];
}

- (void)success {
  NSLog(@"Hooray");
}
...

Recap

The Client instance calls the facade and passes itself as a delegate. The facade in turn calls the low level class instance, passing the facade itself as a delegate. The facade hears the response from the low level class instance, and returns a nicer result to the Client instance. The problem I am working around is how to ensure that the correct facade delegate is getting used when wrapping the low-level delegate’s response.

Reiterating the above, with instances: Client instance A calls the facade [f makeCallWithDelegate:self]. Client instance B also calls the facade [f makeCallWithDelegate:self]. I need to be sure that client A is used as the delegate for client A’s call, and client B is used as the delegate for client B’s call.

Notes impacting the design

The LowLevelClass can’t be modified. If it could, I would perhaps pass in the delegate to call as a “userdata” field, or something … I’m not a fan of that approach anyway, because that pollutes a lower-layer class with knowledge of higher-layer classes.

The facade is a singleton, for a few reasons. Perhaps this could be changed, and I could create multiple facade instances.

Possible Solutions

A. Now, if I could guarantee that the facade was going to be used by a single client at a time, I could just store the_delegate in a Facade member variable, and I could call it in the Facade success: selector; however, I can’t guarantee that. Several different client instances can call the facade, and I need to be sure that each client’s call’s delegate is the client itself, and not some other client (using the instance example above, A needs to handle A’s call, and B needs to handle B’s).

B. I could make the facade a non-singleton class, and just store the_delegate in a member variable. Maybe that’s the best solution … something feels wrong about it though.

C. I was thinking that perhaps I could assign a unique key to each call to makeCallWithDelegate, and the facade singleton instance would store a dictionary of the call keys and the delegate passed in for that call. (Note: The only key that makes sense to me is the actual value of the LowLevelClass pointer — after all, if I generate a random string ID, I’m just deferring the problem — but this somehow feels shaky.) The facade’s “success” method would have access to the dictionary, and so would call the correct delegate:

// Facade.m (pseudocode)
@implementation Facade

- (void)makeCallWithDelegate:(id <FacadeDelegate>) the_delegate
{
  LowLevelClass * llc = ... // get instance
  NSString* uniqueKey = makeUniqueKeyFromPointerValue(llc);
  [self.delegateDictionary setObject:the_delegate forKey:uniqueKey];
  [llc makeAsynchronousCallWithDelegate:self];  // delegate to self, catch events
}

// LowLevelClassDelegate implementation, hands result to the FacadeDelegate 
- (void)success:(LowLevelClass*) c
{
  NSString* uniqueKey = makeUniqueKeyFromPointerValue(c);
  id<FacadeDelegate> del = [self.delegateDictionary objectForKey:uniqueKey];
  [del success]
}

@end

I hope that the above is sufficiently detailed and clear enough. After all that, I feel confused myself (again, new to objective C).

If you’ve made it this far, I thank you (and congratulate you). I’d like to hear any suggestions as to what would be a good design for this problem.

Thanks very much for your time.

  • 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-13T14:24:30+00:00Added an answer on June 13, 2026 at 2:24 pm

    I believe @lnafziger’s correct above, and B is the best answer (change the facade into a regular class, non-singleton, which also moves the design away from singleton issues). I’ll wait to see if any other suggestions arise before accepting this as the answer.

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

Sidebar

Related Questions

I am relatively new to Objective-C / iPhone programming, and have only created single
I'm relatively new to Objective-C + Quartz and am running into what is probably
Im relatively new to the Android world but I have a quick question. I
I'm relatively new to objective-c...I'm using the iphone 3.0 SDK I have a UIView,
I am relatively new to Objective C and need some array help. I have
I'm relatively new to Objective-C and I have an enum with a corresponding array
I am a relatively new iPhone/objective-c programmer and I have an issue that makes
I'm relatively new to the world of Objective-C and have a class that I've
I am relatively new to Objective-C and now I have a problem in my
i m relatively new in Objective C, i have designed a server-client application and

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.