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("变变看");

           }

        }

  • 相关阅读:
    大二下第十三周学习笔记
    对C++多态的一次小分析
    vs2015中用汇编(转)
    挖个坑
    ListCtrl
    获得进程完整路径的第二种方法
    The Meeting Place Cannot Be Changed(二分+eps精度)
    CodeForces 494A
    Anya and Ghosts CodeForces
    寒假给自己立个flag
  • 原文地址:https://www.cnblogs.com/yaoge/p/1815232.html
Copyright © 2011-2022 走看看