设计模式模板方法模式学习教案

上传人:莉**** 文档编号:120776047 上传时间:2022-07-18 格式:PPTX 页数:28 大小:193.84KB
返回 下载 相关 举报
设计模式模板方法模式学习教案_第1页
第1页 / 共28页
设计模式模板方法模式学习教案_第2页
第2页 / 共28页
设计模式模板方法模式学习教案_第3页
第3页 / 共28页
点击查看更多>>
资源描述
会计学1设计模式模板设计模式模板(mbn)方法模式方法模式第一页,共28页。class TestPaperB /试题1 public void TestQuestion1()Console.WriteLine(杨过得到,后来给了郭靖,炼成倚天剑、屠龙刀的玄铁 可能是 a.球磨铸铁 b.马口铁 c.高速合金钢 d.碳素纤维);Console.WriteLine(答案:d);/试题2 public void TestQuestion2()Console.WriteLine(杨过、程英、陆无双铲除了情花,造成 a.使这种植物不再害人 b.使一种珍稀物种灭绝 c.破坏了那个生物圈的生态平衡 d.造成该地区沙漠化 );Console.WriteLine(答案:b);/试题3 public void TestQuestion3()Console.WriteLine(蓝凤凰的致使华山师徒、桃谷六仙呕吐不止,如果(rgu)你是大夫,会给他们 开什么药 a.阿司匹林 b.牛黄解毒片 c.氟哌酸 d.让他们喝大量的生牛奶 e.以上全不对 );Console.WriteLine(答案:a);学生(xu sheng)乙的试卷第2页/共28页第二页,共28页。static void Main(string args)Console.WriteLine(学生(xu sheng)甲的试卷:);TestPaperA studentA=new TestPaperA();studentA.TestQuestion1();studentA.TestQuestion2();studentA.TestQuestion3();Console.WriteLine(学生(xu sheng)乙的试卷:);TestPaperB studentB=new TestPaperB();studentB.TestQuestion1();studentB.TestQuestion2();studentB.TestQuestion3();Console.Read();学生甲和学生乙的试卷(shjun)类非常类似,除了答案不同,没什么区别,如果老师修改题目,2个类都需要修改。第3页/共28页第三页,共28页。class TestPaper /试题1 public void TestQuestion1()Console.WriteLine(杨过得到,后来给了郭靖,炼成倚天剑、屠龙刀的玄铁 可能是 a.球磨铸铁 b.马口铁 c.高速合金钢 d.碳素纤维);Console.WriteLine(答案:b);/试题2 public void TestQuestion2()Console.WriteLine(杨过、程英、陆无双铲除了情花,造成 a.使这种植物不再害人 b.使一种珍稀物种灭绝 c.破坏了那个生物圈的生态平衡 d.造成该地区沙漠化 );Console.WriteLine(答案:a);/试题3 public void TestQuestion3()Console.WriteLine(蓝凤凰的致使华山师徒、桃谷六仙呕吐不止(bzh),如果你是大夫,会给他们 开什么药 a.阿司匹林 b.牛黄解毒片 c.氟哌酸 d.让他们喝大量的生牛奶 e.以上全不对 );Console.WriteLine(答案:c);试卷(shjun)父类第4页/共28页第四页,共28页。学生(xu sheng)甲的试卷 class TestPaperA:TestPaper public new void TestQuestion1()base.TestQuestion1();Console.WriteLine(答案(d n):c);public new void TestQuestion2()base.TestQuestion2();Console.WriteLine(答案(d n):b);public new void TestQuestion3()base.TestQuestion3();Console.WriteLine(答案(d n):a);class TestPaperB:TestPaper public new void TestQuestion1()base.TestQuestion1();Console.WriteLine(答案:d);public new void TestQuestion2()base.TestQuestion2();Console.WriteLine(答案:c);public new void TestQuestion3()base.TestQuestion3();Console.WriteLine(答案:a);学生乙的试卷第5页/共28页第五页,共28页。class TestPaper public void TestQuestion1()Console.WriteLine(杨过得到(d do),后来给了郭靖,炼成倚天剑、屠龙 刀的玄铁可能是 a.球磨铸铁 b.马口铁 c.高速合金钢 d.碳素纤维);Console.WriteLine(答案:+Answer1();protected virtual string Answer1()return;第6页/共28页第六页,共28页。/学生(xu sheng)甲抄的试卷 class TestPaperA:TestPaper protected override string Answer1()return b;protected override string Answer2()return c;protected override string Answer3()return a;/学生(xu sheng)乙抄的试卷 class TestPaperB:TestPaper protected override string Answer1()return c;protected override string Answer2()return a;protected override string Answer3()return a;第7页/共28页第七页,共28页。第8页/共28页第八页,共28页。static void Main(string args)Console.WriteLine(学生(xu sheng)甲抄的试卷:);TestPaper studentA=new TestPaperA();studentA.TestQuestion1();studentA.TestQuestion2();studentA.TestQuestion3();Console.WriteLine(学生(xu sheng)乙抄的试卷:);TestPaper studentB=new TestPaperB();studentB.TestQuestion1();studentB.TestQuestion2();studentB.TestQuestion3();Console.Read();第9页/共28页第九页,共28页。模式动机与定义1模式结构与分析2模式实例与解析3模式效果与应用4第10页/共28页第十页,共28页。第11页/共28页第十一页,共28页。第12页/共28页第十二页,共28页。第13页/共28页第十三页,共28页。第14页/共28页第十四页,共28页。第15页/共28页第十五页,共28页。第16页/共28页第十六页,共28页。极品飞车中有很多的汽车,但是从操作角度看大同小异。无非是起步(qb)(StartUp)、行驶(Run)、停车(Stop)等行为。结合Template Method模式讲就是在这个程序中,结构(对汽车的操作)是稳定的,但是变化在于各个子步骤(操作行为的具体实现)。第17页/共28页第十七页,共28页。public abstract class AbstractCar protected abstract string StartUp();protected abstract string Run();protected abstract string Stop();public void DriveOnTheRoad()Console.WriteLine(StartUp();Console.WriteLine(Run();Console.WriteLine(Stop();在这段代码(di m)中,抽象方法StartUp、Run、Stop叫做primitive operation(原语操作),它们是在子类中的扩展点。AbstractCar中的DriveOnTheRoad方法(fngf)叫做template method(模板方法(fngf)),template method用primitive operation定义一个算法,是相对稳定的部分。(子类中重新定义primitive operation)。第18页/共28页第十八页,共28页。public class BORA:AbstractCar protected override string StartUp()return BORA is StartUp;protected override string Run()return BORA is Running;protected override string Stop()return BORA is Stoped;第19页/共28页第十九页,共28页。static void Main(string args)AbstractCar car=new BORA();car.DriveOnTheRoad();Console.Read();第20页/共28页第二十页,共28页。第21页/共28页第二十一页,共28页。第22页/共28页第二十二页,共28页。第23页/共28页第二十三页,共28页。第24页/共28页第二十四页,共28页。第25页/共28页第二十五页,共28页。第26页/共28页第二十六页,共28页。第27页/共28页第二十七页,共28页。LOGO感谢您的观看(gunkn)!第28页/共28页第二十八页,共28页。
展开阅读全文
相关资源
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 课件教案


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!