
设计模式 - 8) 模板模式
发布日期:2021-05-13 19:47:07
浏览次数:16
分类:博客文章
本文共 1225 字,大约阅读时间需要 4 分钟。
������������������������������������������������������������������������������������������������������������������������������������������������
public class TestPaper{ public void Question1() { Console.WriteLine("This is Question1:"); Console.WriteLine(string.Format("Your answer is {0}", Answer1())); } public void Question2() { Console.WriteLine("This is Question2:"); Console.WriteLine(string.Format("Your answer is {0}", Answer2())); } protected virtual string Answer1() { return string.Empty; } protected virtual string Answer2() { return string.Empty; }}public class TestPaperA : TestPaper{ protected override string Answer1() { return "a"; } protected override string Answer2() { return "b"; }}public class TestPaperB : TestPaper{ protected override string Answer1() { return "aa"; } protected override string Answer2() { return "bb"; }}public class TemplateViewModel{ public TemplateViewModel() { TestPaper a = new TestPaperA(); a.Question1(); a.Question2(); TestPaper b = new TestPaperB(); b.Question1(); b.Question2(); }}
发表评论
最新留言
表示我来过!
[***.240.166.169]2025年04月27日 03时10分24秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Explore Optimization
2021-05-10
Kali Linux 内网渗透教程 - ARP欺骗攻击 | 超详细
2021-05-10
2020Java程序设计基础(华东交通大学)章节测试免费满分答案
2021-05-10
解决数据库报ORA-02289:序列不存在错误
2021-05-10
map[]和map.at()取值之间的区别
2021-05-11
成功解决升级virtualenv报错问题
2021-05-11
【SQLI-Lab】靶场搭建
2021-05-11
【Bootstrap5】精细学习记录
2021-05-11
LeetCode197.打家劫舍
2021-05-11
A simple problem HDU-2522 【数学技巧】
2021-05-11
Struts2-从值栈获取list集合数据(三种方式)
2021-05-11
vscode中快速生成vue模板
2021-05-11
参考图像
2021-05-12
设计模式(18)——中介者模式
2021-05-12
用JavaScript实现希尔排序
2021-05-12
推荐几篇近期必看的视觉综述,含GAN、Transformer、人脸超分辨、遥感等
2021-05-12