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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:44:36+00:00 2026-05-24T21:44:36+00:00

I have some very small classes that I feel should be pulled up but

  • 0

I have some very small classes that I feel should be “pulled up” but the methods are so small I’m not sure. For example, the only thing that’s meaningfully different is the body of the buildFromJSON: selector.

I acknowledge that this is similar to:
Pull-up refactoring, Objective-C
but I feel my question is specific to refactoring very small classes/methods.

Also, not sure it relates to my particular code example, but I’m wondering if a child class says it conforms to a protocol, whether it’s enough that it’s parent actually supply the implementation of required selector(s)?

@implementation AsyncFoo

-(void)dealloc {
    [clientDelegate release];
    [super dealloc];
}

- (id)initWithDelegate: (id <ServiceClientProtocol>) delegate {
    if((self = [super init])) {
        clientDelegate = [delegate retain];
    }
    return self;
}

- (void)buildFromJSON:(NSString*)jsonResponseString {
    [clientDelegate serviceComplete:[RestAdapter buildFooArray: jsonResponseString]];
}

@end



@implementation AsyncBar

-(void)dealloc {
    [clientDelegate release];
    [super dealloc];
}

- (id)initWithDelegate: (id <ServiceClientProtocol>) delegate {
    if((self = [super init])) {
        clientDelegate = [delegate retain];
    }
    return self;
}

- (void)buildFromJSON:(NSString*)jsonResponseString {
    [clientDelegate serviceComplete:[RestAdapter buildBarArray:jsonResponseString]];
}

@end

Answers including code example would be great.

EDIT: Post accepted answer I’d like to add that since I was able to subclass, the derived classes did not need to declare that they conformed to protocol:

@interface Async : NSObject <ModelBuilderProtocol> {
    id <ServiceClientProtocol> clientDelegate;
}
- (void)buildFromJSON:(NSString*)jsonResponseString;
@end

@interface AsyncArtistById : Async
@end 
  • 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-24T21:44:37+00:00Added an answer on May 24, 2026 at 9:44 pm

    You don’t normally retain your delegates as this can cause a retain cycle.

    Knowing what I know from looking at your example I would probably implement like this:

    The super class

    // Async.h
    @interface Async : NSObject
    
    @property (nonatomic, assign) id<ServiceClientProtocol> delegate;
    
    - (void)buildFromJSON:(NSString *)jsonResponseString;
    
    @end
    
    // Async.m
    @implementation Async
    
    @synthesize delegate = _delegate;
    
    - (id)initWithDelegate:(id<ServiceClientProtocol>)delegate 
    {
        self = [super init];
        if(self) {
            _delegate = delegate;
        }
        return self;
    }
    
    - (void)buildFromJSON:(NSString *)jsonResponseString
    {
        // This will ensure that we over ride this method in a sub class
        [NSException raise:NSInternalInconsistencyException 
            format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)];
    }
    
    @end
    

    Concrete subclass AsyncFoo

    // AsyncFoo.h
    @interface AsyncFoo : Async
    @end
    
    // AsyncFoo.m
    @implementation AsyncFoo
    
    - (void)buildFromJSON:(NSString *)jsonResponseString 
    {
        [self.delegate serviceComplete:[RestAdapter buildFooArray: jsonResponseString]];
    }
    
    @end
    

    Concrete subclass AsyncBar

    // AsyncBar.h
    @interface AsyncBar : Async
    @end
    
    // AsyncBar.m
    @implementation AsyncBar
    
    - (void)buildFromJSON:(NSString *)jsonResponseString {
        [self.delegate serviceComplete:[RestAdapter buildBarArray:jsonResponseString]];
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some very basic semaphore code that works great on Linux, but cannot
I have developed some custom DAO-like classes to meet some very specialized requirements for
I am very new to ASP and I have some small project to do,
I am trying to make some small adjustments to a very big website (not
I have a customer with a very small set of data and records that
We have some very large data files (5 gig to 1TB) where we need
I have some very simple code to generate an assembly and invoke a method
I have some very simple XML: <properties> <property> <name>BobFish</name> <explaination>Bob is a fish.</explaination> </property>
I have some VERY simple code to return the title for a section header:
I have no idea why this is happening. I have some very straightforward code,

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.