using System.Collections;
namespace Templates.Observer {
public class Observer {
private Subject mySubject;
public Observer (Subject s){
mySubject = s;
}
public void Update(){
// ...
SubjectState state = mySubject.GetState();
// if (the state is interesting){
// react on state change
// }
}
}
} | |
The Observer class.
A reference to the corresponding
Subject.
The constructor of Observer.
The Update method, activated by
the subject via Notify.
Sends a message back to the subject,
asking what really happend.
|