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

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

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

查看全文
  • 相关阅读:
    easyui 如何引入
    图片切换展示效果
    渐变弹出层
    C# GEP基因化编程
    C#操作内存
    移动的彩虹
    收缩和展开效果
    用SQL语句,删除掉重复项只保留一条
    图片切换,带标题文字
    Sql Server快速建表
  • 原文地址:https://www.cnblogs.com/TivonStone/p/1722076.html
  • Copyright © 2011-2022 走看看