Beispiel #1
0
  public static void main(String[] args) {
    Subject subject = new MySubject();

    Observer observer1 = new MyObserver(1);
    Observer observer2 = new MyObserver(2);
    Observer observer3 = new MyObserver(3);

    subject.attach(observer1);
    subject.attach(observer2);
    subject.attach(observer3);

    subject.notice();

    subject.detach(observer1);

    subject.notice();
  }
Beispiel #2
0
 public static void main(String[] args) {
   Subject subject = new TeacherSubject();
   subject.attach(new Stu1Observer());
   subject.attach(new Stu2Observer());
   subject.publish();
 }
 public HexaObserver(Subject subject) {
   this.subject = subject;
   subject.attach(this);
 }