zoukankan      html  css  js  c++  java
  • 十一.模板模式

    模板方法:

           定义一个操作的算法的骨架,而将一些步骤延迟到子类中。模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤。

    Demo1

           classquestion

        {

           public void ShowQ()

           {

               Console.WriteLine("问题:");

               Console.WriteLine("答案:"+ShowA());

           }

           public virtual string  ShowA()

           {

               return "";

           }

        }

       class question1:question

        {

           public override string ShowA()

           {

               return "A";

           }

        }

    Demo2:

           classfather

        {

           public void Show1()

           {

                Console.WriteLine("这是方法1");

           }

           public virtual void Show2()

           {

               Console.WriteLine("这是可变方法2");

           }

           public void ShowAll()

           {

               Show1();

               Show2();

           }

        }

       class child : father

        {

           public override void Show2()

           {

               base.Show2();

               Console.WriteLine("变变看");

           }

        }

  • 相关阅读:
    pronunciation techniques
    contraction prnounciation
    洛谷P2097 资料分发1 题解
    洛谷P1482 Cantor表(升级版) 题解
    洛谷P1615 西游记公司 题解
    洛谷P2676 超级书架 题解
    洛谷P1554 梦中的统计 题解
    洛谷P1720 月落乌啼算钱 题解
    洛谷P1420 最长连号 题解
    洛谷P1634 禽兽的传染病 题解
  • 原文地址:https://www.cnblogs.com/yaoge/p/1815232.html
Copyright © 2011-2022 走看看