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

           }

        }

  • 相关阅读:
    jsp转向
    什么是 XDoclet?
    tomcat中的几点配置说明
    mysql5问题
    POJ 3734 Blocks
    POJ 2409 Let it Bead
    HDU 1171 Big Event in HDU
    POJ 3046 Ant Counting
    HDU 2082 找单词
    POJ 1286 Necklace of Beads
  • 原文地址:https://www.cnblogs.com/yaoge/p/1815232.html
Copyright © 2011-2022 走看看