Template method pattern: Difference between revisions

Content deleted Content added
WikiCleanerBot (talk | contribs)
m v2.02b - Bot T18 - WP:WCW project (<nowiki> tags)
Citation bot (talk | contribs)
Removed parameters. | You can use this bot yourself. Report bugs here. | Suggested by Abductive | All pages linked from cached copy of User:Abductive/sandbox | via #UCB_webform_linked 893/988
Line 35:
 
The template method is used in frameworks, where each implements the invariant parts of a ___domain's architecture, while providing hook methods for customization. This is an example of [[inversion of control]]. The template method is used for the following reasons.<ref name=":1">{{cite web | url = http://sourcemaking.com/design_patterns/template_method | title = Template Method Design Pattern | publisher = Source Making - teaching IT professional | quote = Template Method is used prominently in frameworks. | accessdate = 2012-09-12}}</ref>
* It lets subclasses implement varying behavior (through [[Method overriding (programming)|overriding]] of the hook methods).<ref name=":3">{{Cite book|title=Pro Objective-C Design Patterns for iOS|last=Chung|first=Carlo|publisher=Apress|year=2011|isbn=978-1-4302-3331-2|___location=Berkeley, CA|pages=266|quote=|via=}}</ref>
* It avoids duplication in the code: the general workflow of the algorithm is implemented once in the abstract class's template method, and necessary variations are implemented in the subclasses.<ref name=":3" />
* It controls the point(s) at which specialization is permitted. If the subclasses were to simply override the template method, they could make radical and arbitrary changes to the workflow. In contrast, by overriding only the hook methods, only certain specific details of the workflow can be changed,<ref name=":3" /> and the overall workflow is left intact.