zoukankan      html  css  js  c++  java
  • 浅尝DesignPattern_Template

    UML:

  • AbstractClass  ()
    • defines abstract primitive operations that concrete subclasses define to implement steps of an algorithm
    • 定义一个抽象的原始操作,来使子类实现算法步骤
    • implements a template method defining the skeleton of an algorithm. The template method calls primitive operations as well as operations defined in AbstractClass or those of other objects.
    • 实现一个定义了算法节后的模版方法.该模版方法需要原始操作和抽象类中定义的操作.
  • ConcreteClass  ()
    • implements the primitive operations to carry out subclass-specific steps of the algorithm
    • 实现原始操作,来实现子类的特殊操作
    1 abstract class AbstractClass
    2 {
    3 public abstract void PrimitiveOperation1();
    4 public abstract void PrimitiveOperation2();
    5
    6 public void TemplateMethod()
    7 {
    8 PrimitiveOperation1();
    9 PrimitiveOperation2();
    10 Console.WriteLine("");
    11 }
    12 }
    代码
    代码
    代码
    1 #region Template
    2 AbstractClass aA = new ConcreteClassA();
    3 aA.TemplateMethod();
    4 AbstractClass aB = new ConcreteClassB();
    5 aB.TemplateMethod();
    6 #endregion

    模版方法模式:定义一个操作中的算法股价,而将一些步骤延迟到子类中.模版方法是的子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤.

    模版方法模式是通过把不变行为搬移到超类,取出子类中的重复代码来体现它的优势.它提供了一个很好的复用平台.

查看全文
  • 相关阅读:
    Spring@Profile注解
    day 32 子进程的开启 及其用法
    day 31 udp 协议SOCK_DGRAM
    day 30 客户端获取cmd 命令的步骤
    day 29 socket 理论
    day 29 socket 初级版
    有关 组合 继承
    day 27 多态 接口 类方法 静态方法 hashlib 摘要算法模块
    新式类和经典类的区别
    day 28 hasattr getattr serattr delattr 和带__内置__ 类的内置方法
  • 原文地址:https://www.cnblogs.com/TivonStone/p/1722076.html
  • Copyright © 2011-2022 走看看