码迷,mamicode.com
首页 > 其他好文 > 详细

Template Method Design Pattern

时间:2020-06-16 14:53:55      阅读:57      评论:0      收藏:0      [点我收藏+]

标签:http   ati   get   eve   com   actor   span   step   source   

 

 

 

 

 

 

Template Method Design Pattern

Rules of thumb

  • Strategy is like Template Method except in its granularity粒度.
  • Template Method uses inheritance to vary part of an algorithm. Strategy uses delegation to vary the entire algorithm.
  • Strategy modifies the logic of individual objects. Template Method modifies the logic of an entire class.
  • Factory Method is a specialization of Template Method.

 

Template Method

 Relations with Other Patterns

  • Factory Method is a specialization of Template Method. At the same time, a Factory Method may serve as a step in a large Template Method.

  • Template Method is based on inheritance: it lets you alter parts of an algorithm by extending those parts in subclasses. Strategy is based on composition: you can alter parts of the object’s behavior by supplying it with different strategies that correspond to that behavior. Template Method works at the class level, so it’s static. Strategy works on the object level, letting you switch behaviors at runtime.

 

Template Method Design Pattern

标签:http   ati   get   eve   com   actor   span   step   source   

原文地址:https://www.cnblogs.com/chucklu/p/13140720.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!