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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:04:30+00:00 2026-05-28T13:04:30+00:00

I plan to override a method in the subclass if a boolean is set

  • 0

I plan to override a method in the subclass if a boolean is set to a certain value, and then to switch this value, and have thought of two options:

1. Calling super and checking success

// Superclass
-(BOOL) showEngine
    BOOL result = !self.isEngineActive;
    if (result) {
        // Does something common to both super and subclass
        self.isEngineActive = YES;
    }
    return result;
}

// Subclass override
-(BOOL) showEngine
    BOOL result = [super showEngine];
    if (result) {
        // Does something unique to subclass
    }
    return result;
}

2. Delegate to a second method

// Superclass
-(void) showEngine
    if (!self.isEngineActive) {
        // Delegate
        showEngineNow();
        // Does something common to both super and subclass
        self.isEngineActive = YES;
    }
}

// Subclass override
-(void) showEngineNow() {
    [super showEngineNow];
    // Does something unique to subclass
}

The first method has the negative effect of having to call super and check the result, whereas the second has the negative baggage of a second method call to the delegate. Which would be the better way, and is there one I haven’t thought of?

  • 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-28T13:04:31+00:00Added an answer on May 28, 2026 at 1:04 pm

    negative effect of having to call super

    Calling the super implementation is pretty common when overriding a method. I don’t see this as a negative. It’s not clear from the question what you are trying to acheive, but I’d go with option 1 – why introduce more complexity?

    This is assuming that the unspecified //stuff you are doing in the super implementation should also be done by the subclass. If not, you will need to split out into separate methods.

    I don’t think you are using “delegate” as it is intended in Cocoa. If it’s just another method in the same class, it isn’t a delegate. A delegate is a separate object that conforms to a known protocol.

    If you feel that the methods are getting too long and doing too many things, then by all means break them up and override only the relevant parts in your subclass. In that case option 2 is your best bet, but don’t call it a delegate.

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

Sidebar

Related Questions

I plan to have 2 projects. 1. mbtech.crm.mvc 2. mbtech.crm.tests I will have a
I have a conundrum, I do know how to call method from other activity..
Plan to have a data structure to store temporary binary data in the memory
I plan on developing Excel Add-ins and I have looked around on ways of
I have two collections of my own reference-type objects that I wrote my own
I have created one gridview and use custom adapter for that. I added two
My plan is to create a a two-pane page using ASP MVC 3. The
I plan to build something like pricegrabber.com/google product search. Assume I already have the
I have an object called FormObject that contains two ArrayLists - oldBooks and newBooks
I plan to be storing all my config settings in my application's app.config section

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.