Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace TheStoryOfCat
{
Class Program
{
Static void Main (string [] args)
{
Cat cat = new Cat () {Name = "Petal "};
Mouse mouse = new Mouse () {Name = "Jack "};
Cat. CatMonitorEvent + = cat. Move;
Cat. CatMonitorEvent + = mouse. Move;
// Master
Master master = new Master (cat) {Name = "Old Boss "};
Cat. Run ();
Console. ReadKey ();
}
}
Public delegate void MonitorHandle ();
Public class Cat
{
Public string Name;
Public event MonitorHandle CatMonitorEvent;
Public Cat (){
}
Public void Move ()
{
Console. WriteLine ("Cat:" + this. Name + "Moving ");
}
Public void Run ()
{
If (CatMonitorEvent! = Null)
CatMonitorEvent ();
}
}
Public class Mouse
{
Public string Name;
Public Mouse (){
}
Public void Move ()
{
Console. WriteLine ("Mouse:" + this. Name + "Moving ");
}
}
Public class Master
{
Public string Name;
/// <Summary>
/// Injection
/// </Summary>
/// <Param name = "cat"> </param>
Public Master (Cat cat)
{
If (cat! = Null)
Cat. CatMonitorEvent + = Move;
}
Public void Move ()
{
Console. WriteLine ("Master:" + this. Name + "Moving ");
}
}
}
Statement 2:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace TheStoryOfCat
{
Class Program
{
Static void Main (string [] args)
{
Cat cat = new Cat () {Name = "Petal "};
Mouse mouse = new Mouse () {Name = "Jack "};
Cat. CatMonitorEvent + = cat. Move;
Cat. CatMonitorEvent + = mouse. Move;
// Master
Master master = new Master (cat) {Name = "Old Boss "};
Cat. Run (new MonitorEventArgs (20 ));
Console. WriteLine ("---------- gorgeous split line -------------");
Cat. Run (new MonitorEventArgs (70 ));
Console. ReadKey ();
}
}
Public class MonitorEventArgs: EventArgs
{
Public int Sound;
Public MonitorEventArgs (int _ Sound ){
This. Sound = _ Sound;
}
}
Public delegate void MonitorHandle (object obj, MonitorEventArgs arg );
/// <Summary>
/// Cat
/// </Summary>
Public class Cat
{
Public string Name;
Public event MonitorHandle CatMonitorEvent;
Public Cat (){
}
Public void Move (object obj, MonitorEventArgs arg)
{
Console. WriteLine ("{0} current call {1} decibel", this. Name, arg. Sound );
}
Public virtual void Run (MonitorEventArgs arg)
{
If (CatMonitorEvent! = Null)
CatMonitorEvent (this, arg );
}
}
/// <Summary>
/// Mouse
/// </Summary>
Public class Mouse
{
Public string Name;
Public Mouse (){
}
/// <Summary>
/// The call of a cat is not expected if it is lower than 50 decibels
/// </Summary>
/// <Param name = "obj"> </param>
/// <Param name = "arg"> </param>
Public void Move (object obj, MonitorEventArgs arg)
{
If (arg = null)
Return;
String result = "unexpected ";
If (arg. Sound> 50)
Result = "run ";
Console. WriteLine ("{0} Heard, current cat call {1} decibel, {2}", this. Name, arg. Sound, result );
}
}
/// <Summary>
/// Master
/// </Summary>
Public class Master
{
Public string Name;
/// <Summary>
/// Injection
/// </Summary>
/// <Param name = "cat"> </param>
Public Master (Cat cat)
{
If (cat! = Null)
Cat. CatMonitorEvent + = Move;
}
Public void Move (object obj, MonitorEventArgs arg)
{
If (arg = null)
Return;
String result = "Cats lack of air ";
If (arg. Sound> 50)
Result = "the cat is in good state ";
Console. WriteLine ("host {0}, heard the current call of the cat {1} decibel, {2}", this. Name, arg. Sound, result );
}
}
}