模板方法模式

来源:互联网 发布:电脑怎么下载淘宝 编辑:程序博客网 时间:2024/06/05 19:10



模板方法模式:

我的理解是:重载虚函数



using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 模板方法{    class TestPaper    {        public void TestQuestion()        {            Console.WriteLine(" 杨过得到,后来给了郭靖,炼成倚天剑、屠龙刀"+                "的玄铁可能是[ ]\n a.球磨铸铁 b.马口铁 c.高速合金钢 d.碳素纤维 ");            Console.WriteLine("答案:" + Answer());        }       protected virtual string Answer()        {           return " ";        }    }    class TestPaperA:TestPaper    {        override protected string Answer()        {            return "a";        }    }    class TestPaperB : TestPaper    {        protected  override string Answer()        {            return "b";        }    }    class Program    {        static void Main(string[] args)        {            TestPaper a = new TestPaperA(); a.TestQuestion();            TestPaper b = new TestPaperB(); b.TestQuestion();        }    }}

 杨过得到,后来给了郭靖,炼成倚天剑、屠龙刀的玄铁可能是[ ] a.球磨铸铁 b.马口铁 c.高速合金钢 d.碳素纤维答案:a 杨过得到,后来给了郭靖,炼成倚天剑、屠龙刀的玄铁可能是[ ] a.球磨铸铁 b.马口铁 c.高速合金钢 d.碳素纤维答案:b请按任意键继续. . .