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.