Issuvision how to complete the registration and notification of the observer mode

zhaozj2021-02-17  45

It is well known that the observer mode focus is a message notification of the observer object when the observer object is registered and the Subject state changes. So, how do I achieve this in IssuVision (Sample Program of Microsoft Intelligent Client)? Here, I propose my own opinion, I hope everyone is criticized.

In IssuVision, the system defines a IssueSubject class that implements the ISUBJECT interface, and each observer object implements an IOBSERVER interface, which includes an isubject object. Registration and event rating is done here:

M_issueSubject = New IssueSubject (this.components);

Panestaff.subject = m_issuesubject;

Panemiddle.subject = m_issuesubject;

PANERIGHT.SUBJECT = m_issuesubject;

Panechart.subject = m_issueesubject;

Paneconflict.subject = m_issuesubject;

The system first created an instance of an IssueSubject class, and then let all the observer objects share this instance so that registration is completed. However, things have not yet finished, we go deep into Subject's registration, 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_issued);

}

}

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_issued);

}

}

In these two registrations, m_subject points to the same IssueSubject object, which guarantees that they share the same data source, while the Event Handle of the IssueSubject object is hung in the membership method of the viewer. This ensures that the IssueSubject object triggers the event, and the message can be notified to this observation. 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_issued);

M_Subject.issuedataChanged = new issuesubject.issueDataChangeDeventHandler (this.subject_issued);

Here, the m_subject.issueDataChange event corresponds to two event response methods, which guarantees that the IssueDataChange event can simultaneously notify multiple observer objects at the same time, and only the objects of the message are ordered. Similarly, we are also very easy to order or deselect a particular message for an observer object. Through the above introduction, I think everyone should understand the registration and notice method of the observer mode? If you have any errors or insufficient places, please take your ax.

转载请注明原文地址:https://www.9cbs.com/read-28641.html

New Post(0)