Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>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?</p> </blockquote> <p>Yes, this is much more that just overriding a base class method. Template methods is a way to implement an algorithm where some steps are subclass dependent. For example consider a method in Base which has three major steps, f1, f2 and f3. Each steps contains a number of statements. Here f1 and f3 are same in all subclass, but f2 is subclass dependent. So what to do here? You can override the whole method in subclass copying statements of f1 and f3, but that is a waste. So you provide only f2 in subclass. And in this is way you define the algorithm (execute f1, then execute f2, then execute f3) in base class but provide overriding hooks for subclasses (f2). Note that, template method in base class is final, so subclass can't change the algorithm, e.g. it can't change the order of f1, f2 and f3, neither subclass can omit the steps f1, f3.</p> <p>In short, Template Methods pattern is not just overriding, it is the use of inheritance to handle some specific situations. This is not Obj-C specific, and I can't provide you anything specific to Obj-C. To get an overall idea about this pattern, I recommend the followings:</p> <ol> <li><a href="http://rads.stackoverflow.com/amzn/click/0201633612" rel="nofollow">Design Patterns book by GoF</a></li> <li><a href="http://rads.stackoverflow.com/amzn/click/0596007124" rel="nofollow">Head First Design Patterns</a></li> <li><a href="http://en.wikipedia.org/wiki/Template_method_pattern" rel="nofollow">Wikipedia article on Template Method</a></li> </ol> <p>And there are also tons of tutorials/articles on web. The basic idea is not Obj-C dependent.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload