您现在的位置是:首页 >

一叶知秋 浅尝DesignPattern

火烧 2023-03-14 05:33:43 1066
浅尝De ig Patter   UML:    · A tractCla   ·defi e a tract rimitive o eratio that co crete u cla e defi

浅尝DesignPattern  

  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

  ·实现原始操作 来实现子类的特殊操作

       abstract class AbstractClass

        {

            public abstract void PrimitiveOperation ();

            public abstract void PrimitiveOperation ();

  

            public void TemplateMethod()

            {

                PrimitiveOperation ();

                PrimitiveOperation ();

一叶知秋 浅尝DesignPattern

                Console WriteLine( );

            }

        }

                #region Template

                AbstractClass aA = new ConcreteClassA();

                aA TemplateMethod();

                AbstractClass aB = new ConcreteClassB();

                aB TemplateMethod();

                #endregion

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

lishixinzhi/Article/program/net/201311/13987  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码