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

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

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

查看全文
  • 相关阅读:
    python 字典转对象实现
    漏洞复现的整理
    mlx90614红外传感器
    【小程序码】登录的技术实现案例
    Spring mvc Aop
    MSHFLEXGRID常用的属性,方法事件
    InsertAuditEntryNew
    Froggy 的 CSP-2021 S1 游记
    JOI Open 偷学记录
    生产订单工序新增、修改、删除——CO_SE_PRODORD_OPR_CREATE、CO_SE_PRODORD_OPR_CHANGE、CO_SE_PRODORD_OPR_DELETE
  • 原文地址:https://www.cnblogs.com/TivonStone/p/1722076.html
  • Copyright © 2011-2022 走看看