How issuvision registers and notifies the observer Mode

Source: Internet
Author: User

 

 

As we all know, the focus of the observer (observer) mode is to register the observer object and notify the message of the observer object when the subject status changes. So how does one implement this in issuvision (Microsoft Smart Client sample program? Here, I put forward my own opinions and hope you will criticize and correct them.

In issuvision, the system defines an issuesubject class, which implements the isubject interface and implements the iobserver interface for each observer object. This interface includes an isubject object. Registration and event level are completed here:

M_issuesubject = new issuesubject (this. components );

 

Panestaff. Subject = m_issuesubject;

Panemiddle. Subject = m_issuesubject;

Paneright. Subject = m_issuesubject;

Panechart. Subject = m_issuesubject;

Paneconflict. Subject = m_issuesubject;

 

The system first creates an issuesubject class instance, and then shares all the observer objects with this instance. This completes the registration. However, the process is not complete yet. Let's dive into the subject registration operation to see what happened in it:

Registration of panemiddle:

Public isubject subject

{

Set

{

M_subject = (issuesubject) value;

Issuelist. Subject = m_subject;

M_subject.issuedatachanged + = new issuesubject. issuedatachangedeventhandler (this. subject_issuedatachanged );

}

}

 

Registration of paneright

Public isubject subject

{

Set

{

M_subject = (issuesubject) value;

M_subject.positionchanged + = new issuesubject. positionchangedeventhandler (this. subject_positionchanged );

M_subject.issuedatachanged + = new issuesubject. issuedatachangedeventhandler (this. subject_issuedatachanged );

}

}

In the two registrations, m_subject points to the same issuesubject object, which ensures that they share the same data source, at the same time, the event handler of the issuesubject object is mounted to the member method of this observer. This ensures that the message can be sent to the observer when the issuesubject object triggers an event. Further, let's take a look at the two lines of code in these two registration methods:

M_subject.issuedatachanged+ = New issuesubject. issuedatachangedeventhandler (this. subject_issuedatachanged );

 

M_subject.issuedatachanged+ = New issuesubject. issuedatachangedeventhandler (this. subject_issuedatachanged );

 

Here, the m_subject.issuedatachange event corresponds to two event response methods, which ensures that multiple observer objects are notified at the same time when the issuedatachange event occurs, and only the objects ordered for the message are notified. Similarly, we can easily order or cancel a specific message for an observer object.

 

After the above introduction, I think you should understand the registration and notification methods of the observer mode? If there are errors or deficiencies, please correct them.

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.