设计模式 - 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();    }}
上一篇:设计模式 - 9) 外观模式
下一篇:设计模式 - 7) 原型模式

发表评论

最新留言

表示我来过!
[***.240.166.169]2025年04月27日 03时10分24秒