Message subscription and delivery design modes in C #

Source: Internet
Author: User

From: http://blog.csdn.net/truexf/archive/2008/05/04/2378590.aspx

Application of the message subscription and delivery design model in the "platform-plug-in" Software Architecture Design

 

Define two interfaces

/* Message Receiver */

Interface imsgreceiver

{

Void processmessage (INT message, object OBJ); // Message Processing

Imsgsender getsender; // gets the message sender.

}

 

/* Message sender */

Interface imsgsender

{

Void bookmessage (imsgreceiver receiver, int message); // message subscription

Void dispatchmessage (INT message );

}

 

/* Message subscription record */

Struct msgreceiverinfo

{

Imsgreceiver extends er;

Int message;

}

 

/* Implement imsgsender in the system form framework */

Class baseform: form, imsgsender

{

Msgreceiverinfo array [] fmsgreceivers;/* used to save the message subscriber */

Public void bookmessage (imsgreceiver receiver, int message)

{

/* Add the consumer er to the fmsgreceivers list */

}

Public void dispatchmessage (INT message)

{

/* Iterate fmsgreceivers and call processmessage of the processmesser. */

}

 

// Call dispatchmessage in a specific event of the following framework

Protected void onformshow {...}

Protected void onformclose {...}

Protected void onformstatechange (State state ){...}

}

 

// Business control that implements the Message Receiver imsgreceiver

Class mycomponent: component, imsgreceiver

{

Void processmessage (INT message, object OBJ)

{

/* Handle a specific message */

}

Imsgsender getsender {

/* Return the framework of the control instance */

}

 

 

Void mycomponent {

 

/* Subscribe to messages in the constructor or other initialization areas */

 

Getsender. bookmessage (this, XXX );

 

}

 

 

}

 

 

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.