模板方法(Template Method)模式
?图2-1:Template模式结构图??
///?<summary>
????///?Benchmark
????///?</summary>
????public?abstract?class?AbstractClass
????{
????????public?void?TemplateMethod()
????????{
????????????this.Primitive1();
????????????this.Primitive2();
????????}
????????protected?abstract?void?Primitive1();
????????protected?abstract?void?Primitive2();
????}
????public?class?ConcreteClass1?:?AbstractClass
????{
????????public?ConcreteClass1()
????????{
????????}
????????protected?override?void?Primitive1()
????????{
????????????Console.WriteLine("ConcreteClass1μ?Operation1");
????????}
????????protected?override?void?Primitive2()
????????{
????????????Console.WriteLine("ConcreteClass1μ?Operation2");
????????}
????}
????public?class?ConcreteClass2?:?AbstractClass
????{
????????public?ConcreteClass2()
????????{
????????}
????????protected?override?void?Primitive1()
????????{
????????????Console.WriteLine("ConcreteClass2μ?Operation1");
????????}
????????protected?override?void?Primitive2()
????????{
????????????Console.WriteLine("ConcreteClass2μ?Operation2");
????????}
????}
///?<summary>
????///?Class1
????///?</summary>
????class?Class1
????{
????????///?<summary>
????????///
????????///?</summary>
????????[STAThread]
????????static?void?Main(string[]?args)
????????{
????????????//
????????????//?TODO:
????????????//
????????????AbstractClass?tmp1?=?new?ConcreteClass1();
????????????tmp1.TemplateMethod();
????????????tmp1?=?new?ConcreteClass2();
????????????tmp1.TemplateMethod();
????????????Console.Read();
????????}
????}
http://www.cnblogs.com/zhenyulu/articles/79894.html