Ii. template method pattern (template method mode)

Source: Internet
Author: User
<% @ 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 " ;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.