asp net 3.5unleashed

Page 203

Figure 11-1 : Architecting an application to use events Here’s how the application illustrated in Figure 11-1 works. The application initializes by constructing an instance of MailManager. MailManager offers a MailMsg event. When the Fax and Pager objects are constructed, they register themselves with MailManager’s MailMsg event so that MailManager knows to notify the Fax and Pager objects when new e-mail messages arrive. Now, when MailManager receives a new e-mail message (sometime in the future), it will fire the MailMsg event, giving all the registered objects an opportunity to process the new message any way they want.

Designing a Type That Exposes an Event Let’s look at the type definition for MailManager to really understand all the steps you must take to properly define an event member using Microsoft’s recommended design pattern: class MailManager { // The MailMsgEventArgs type is defined within the MailManager type. public class MailMsgEventArgs : EventArgs {

// 1. Type defining information passed to receivers of the event public MailMsgEventArgs( String from, String to, String subject, String body) {

this.from

= from;

this.to

= to;

this.subject = subject; this.body

= body;


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.