private void button1_Click(object sender, EventArgs e) { //创建火警警报实例 FireAlarm myFireAlarm = new FireAlarm(); // 创建解决火情的实例,alarm是参数 FireHandlerClass myFireHandler = new FireHandlerClass(myFireAlarm); //创建一些火情 myFireAlarm.ActivateFireAlarm("Kitchen", 3); myFireAlarm.ActivateFireAlarm("Study", 1); myFireAlarm.ActivateFireAlarm("Porch", 5); return; }
public FireHandlerClass(FireAlarm fireAlarm) { // ExtinguishFire.添加一个包含处理火情的函数的委托,,所以当警报响起时,会接下来执行这个函数 fireAlarm.FireEvent += new FireAlarm.FireEventHandler(ExtinguishFire); }