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

           }

        }

  • 相关阅读:
    HTTP状态码
    CentOS 7 上安装vim(默认未安装)
    yum安装提示Another app is currently holding the yum lock; waiting for it to exit...
    CentOS 7 安装telnet服务
    shell编程
    shell基础
    ssh相关命令
    ssh无密码连接
    centos7小命令
    日志管理
  • 原文地址:https://www.cnblogs.com/yaoge/p/1815232.html
Copyright © 2011-2022 走看看