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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:06:05+00:00 2026-05-26T20:06:05+00:00

So I’ve been reading about template methods on Objective-C and I am trying to

  • 0

So I’ve been reading about template methods on Objective-C and I am trying to understand what’s so special about them. From my understanding any method in a Base class can be over-ridden and super can be called? So is a template method anything more than overriding a method in the base class?

If I’m wrong, can you please explain what a template-method-pattern is, and can you provide an example?

  • 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-26T20:06:06+00:00Added an answer on May 26, 2026 at 8:06 pm

    Yes, the template pattern is a bit more than just overriding a method in the base class.

    Template pattern can be used when an outline of an algorithm is concretely defined, however the steps of the algorithm are left abstract. That means that the steps can be implemented in different ways. But, the general outline of the algorithm is not expected to change.

    An example that I have just created on the fly:

    class Life {
    
       public method goThroughTheDay(){
         goToWork();
         eatLunch();
         comeBackHome();
         programABitMore();
       }
       abstract method goToWork();
       abstract method eatLunch();
       abstract method comeBackHome();
       abstract method programABitMore();
    }
    
    class GoodLife extends Life {
       //override all the abstract methods here
    }
    
    //The client application
    Life life = new GoodLife();
    life.goThroughTheDay();
    

    Basically, the way a day is expected to run down is concretely defined in the Life class. However, the details of the process are taken care by the subclass (ie. GoodLife). GoodLife class will implement steps very differently than a possible ToughLife class.

    There are some variations to this pattern; for example some of the steps can also be concretely defined. In the example, the eatLunch() can be concretely defined in the Life class; meaning that the subclasses are not expected to change this behaviour.

    The pattern makes a lot of sense if you have a relatively complex algorithm that could be implemented in different ways.

    ======================================

    I somehow missed the part with Objective-C in my answer. Here is how it would look in Objective-C:

    @interface Life : NSObject
    
    - (void) goThroughTheDay;
    
    - (void) goToWork; // Abstract
    - (void) eatLunch; // Abstract
    - (void) comeBackHome; // Abstract
    - (void) programABitMore; // Abstract
    
    @end
    
    @implementation Life
    
    - (void) goThroughTheDay {
    
        [self goToWork];
        [self eatLunch];
        [self comeBackHome];
        [self programABitMore];
    }
    
    - (void) goToWork { [self doesNotRecognizeSelector:_cmd]; }
    - (void) eatLunch { [self doesNotRecognizeSelector:_cmd]; }
    - (void) comeBackHome { [self doesNotRecognizeSelector:_cmd]; }
    - (void) programABitMore { [self doesNotRecognizeSelector:_cmd]; }
    
    @end
    
    @interface GoodLife : Life
    
    @end
    
    @implementation GoodLife
    
    - (void) goToWork { NSLog(@"Good Work"); }
    - (void) eatLunch { NSLog(@"Good Lunch"); }
    - (void) comeBackHome { NSLog(@"Good Comeback"); }
    - (void) programABitMore { NSLog(@"Good Programming"); }
    
    @end
    

    Objective-C doesn’t have built-in support for abstract classes, so I worked around it using the doesNotRecognizeSelector: method. A lot more details about the abstract classes & Objective-C can be found here.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am reading a book about Javascript and jQuery and using one of the
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

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.