<% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Template Method pattern. aspx. CS " Inherits = " Pattern_template_method_pattern " %>
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head Runat = "Server" >
< Title > Untitled page </ Title >
</ Head >
< Body >
< Form ID = "Form1" Runat = "Server" >
< Div >
< ASP: textbox ID = "Tb_result" Runat = "Server" Textmode = "Multiline" Rows = "5" > </ ASP: textbox >
< ASP: button ID = "Bt_submit" Runat = "Server" Onclick = "Bt_submit_click" Text = "Template method pattern" />
</ Div >
</ Form >
</ Body >
</ Html > Using System;
Using System. Data;
Using System. configuration;
Using System. collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. webcontrols;
Using System. Web. UI. webcontrols. webparts;
Using System. Web. UI. htmlcontrols;
/// <Summary>
/// Template Method Mode
/// TIPS: You can define the sharing process first, and implement different features in a specific environment. It is scalable!
/// </Summary>
Public Partial Class Pattern_template_method_pattern: system. Web. UI. Page
{
Protected Void Page_load ( Object Sender, eventargs E)
{
}
Protected Void Bt_submit_click ( Object Sender, eventargs E)
{
Concrete C = New Concrete ();
Tb_result.text = C. templatemethod ();
}
}
/// <Summary>
/// Abstract template type
/// </Summary>
Public Abstract Class Abstracttemplate
{
Public Abstract String Operation1 ();
Public Abstract String Operation2 ();
Public String Templatemethod () // The operator sub-method can also be used in 'actual detection board class '.
{
Return Operation1 () + " And " + Operation2 ();
}
}
/// <Summary>
/// Practical Understanding
/// </Summary>
Public Class Concrete: abstracttemplate
{
Public Override String Operation1 ()
{
Return " Operation1 " ;
}
Public Override String Operation2 ()
{
Return " Operation2 " ;
}
}