Delegate: Answers to the interview questions about cats, mice, and masters.
Source: Internet
Author: User
Using System;
Using System. collections;
Using System. componentmodel;
Using System. Data;
Using System. drawing;
Using System. Web;
Using System. Web. sessionstate;
Using System. Web. UI;
Using System. Web. UI. webcontrols;
Using System. Web. UI. htmlcontrols;
Namespace Aspnettest. Common
{
/**/ /// <Summary>
///The abstract description of define_delegate_catmouse.
/// </Summary>
Public Delegate Void Shouteventhandler ();
Public Class Define_delegate_catmouse: system. Web. UI. Page
{
Private Void Page_load ( Object Sender, system. eventargs E)
{
Cat = New CAT ();
Mouse mouse1 = New Mouse (CAT, " Mouse 1 " );
Mouse mouse2 = New Mouse (CAT, " Rat 2 " );
Master = New Master (CAT );
Cat. Shout ();
// Place users hereCodeTo initialize the page
}
Code generated by web Form Designer # Region Code generated by web Form Designer
Override Protected Void Oninit (eventargs E)
{< br> //
// codegen: This call is ASP.. NET web form designer.
//
initializecomponent ();
base . oninit (E);
}
/**/ /// <Summary>
///The designer supports the required methods-do not use the code editor to modify
///The content of this method.
/// </Summary>
Private Void Initializecomponent ()
{
This. Load+ = NewSystem. eventhandler (This. Page_load );
}
# Endregion
}
Public Abstract Class Actionsubject
{
Public Shouteventhandler onshout;
Protected Void Affectresponse ()
{
If ( This . Onshout ! = Null )
{
This. Onshout ();
}
}
}
Public Class Cat: actionsubject
{
Public Void Shout ()
{
Httpcontext. Current. response. Write ("The cat shouted! <Br>");
Affectresponse ();
}
}
Public Abstract Class Affectsubject
{
Public Affectsubject (actionsubject)
{
Actionsubject. onshout+ = NewShouteventhandler (response );
}
Public Abstract Void Response ();
}
Public Class MASTER: affectsubject
{
Public Master (actionsubject ): Base (Actionsubject)
{
}
Public Override Void Response ()
{
Httpcontext. Current. response. Write ("The host woke up! <Br>");
}
}
Public Class Mouse: affectsubject
{
Private String Name;
Public Mouse (actionsubject, String Name ): Base (Actionsubject)
{
This. Name=Name;
}
Public Override Void Response ()
{
Httpcontext. Current. response. Write (This. Name+ "Run! <Br>");
}
}
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.