Template method pattern: Difference between revisions

Content deleted Content added
Citation bot (talk | contribs)
m Alter: title. Add: title-link. | You can use this bot yourself. Report bugs here. | Activated by User:Neko-chan | Category:Software design patterns | via #UCB_Category
Line 4:
{{expert needed|date=May 2016}}
}}
In [[object-oriented programming]], the '''template method''' is one of the [[behavioral pattern|behavioral]] [[software design pattern|design pattern]]<nowiki/>s identified by Gamma et al.<ref name=":0">{{cite book|title=[[Design Patterns]]|last1=Gamma|first1=Erich|last2=Helm|first2=Richard|last3=Johnson|first3=Ralph|last4=Vlissides|first4=John|publisher=Addison-Wesley|year=1994|isbn=0-201-63361-2|pages=[https://archive.org/details/designpatternsel00gamm/page/325 325–330]|chapter=Template Method|authorlink1=Erich Gamma|authorlink2=Richard Helm|authorlink3=Ralph Johnson (computer scientist)|authorlink4=John Vlissides|title-link=Design Patterns}}</ref> in the book ''[[Design Patterns]]''. The template method is a method in a superclass, usually an abstract superclass, and defines the skeleton of an operation in terms of a number of high-level steps. These steps are themselves implemented by additional ''helper methods'' in the same class as the template method.
 
The ''helper methods'' may be either ''[[Abstract method|abstract methods]]'', for which case subclasses are required to provide concrete implementations, or ''[[hook methods]],'' which have empty bodies in the superclass. [[Subclass (computer science)|Subclass]]es can (but are not required to) customize the operation by [[Method overriding|overriding]] the hook methods. The intent of the template method is to define the overall structure of the operation, while allowing subclasses to refine, or redefine, certain steps.<ref name=":2">{{cite book|url=http://shop.oreilly.com/product/9780596007126.do|title=Head First Design Patterns|last2=Freeman|first2=Elisabeth|last3=Sierra|first3=Kathy|last4=Bates|first4=Bert|publisher=O'REILLY|year=2004|isbn=978-0-596-00712-6|editor-last=Hendrickson|editor-first=Mike|volume=1|___location=|pages=289, 311|format=paperback|quote=|editor-last2=Loukides|editor-first2=Mike|via=|last1=Freeman|first1=Eric|accessdate=2012-09-12}}</ref>