using System;
namespace Pattern
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public abstract class template
{
public template()
{
//
// TODO: Add constructor logic here
//
}
public abstract string getstring();
public void act()
{
string a=getstring();
System.Console.WriteLine( a+"****"+a);
}
}
public class temp1 :template
{
private string a;
public temp1(string temp)
{
a=temp;
}
public override string getstring()
{
return a;
}
}
}
// 模板模式
// template a=new temp1("kkk");
// a.act();
// a=new temp1("XXX");
// a.act();
博客展示了一段C#代码,实现了模板模式。定义了抽象类template,包含抽象方法getstring和具体方法act。还定义了继承自template的temp1类,重写了getstring方法。最后给出了使用示例,体现了模板模式在C#中的应用。
346

被折叠的 条评论
为什么被折叠?



