zoukankan      html  css  js  c++  java
  • Template Method Design Pattern

    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.

  • 相关阅读:
    max_element( )
    dp
    dfs
    dp
    区间dp
    树形dp
    dp-最长回文串
    go 结构体函数
    go 结构体初始化
    Golang数组和切片的区别
  • 原文地址:https://www.cnblogs.com/chucklu/p/13140720.html
Copyright © 2011-2022 走看看