int main(int argc, char* argv[]) { ConcreteSubject* sub = new ConcreteSubject(); Observer* o1 = new ConcreteObserverA(sub); Observer* o2 = new ConcreteObserverB(sub); o1->PrintInfo(); o2->PrintInfo(); sub->SetState("old"); sub->Notify(); o1->PrintInfo(); o2->PrintInfo(); sub->SetState("new"); sub->Notify(); o1->PrintInfo(); o2->PrintInfo(); delete o1; delete o2; delete sub; return 0; }
int main() { ConcreteSubject* s = new ConcreteSubject(100); s->attach(new ConcreteObserver("20160701",s)); s->attach(new ConcreteObserver("20160705",s)); s->setState(200); s->notify(); return 0; }
int main(int argc, char* argv[]) { ConcreteSubject* sub = new ConcreteSubject(); Observer* o1 = new ConcreteObserverA(sub); Observer* o2 = new ConcreteObserverB(sub); sub->SetState("old"); sub->Notify(); sub->SetState("new"); //也可以由 Observer 调用 sub->Notify(); return 0; }
int main() { ConcreteSubject * subject = new ConcreteSubject(); subject->Attach(new ConcreteObserver(subject, "zhaohua")); subject->Attach(new ConcreteObserver(subject, "lichao")); subject->SetState("Doc Yang comes here !!!"); subject->Notify(); return 0; }
int main(){ int i=1; ConcreteSubject * CS = new ConcreteSubject(); Observer *o1 = new hexObser(CS); Observer *o2 = new octObser(CS); Observer *o3 = new binObser(CS); do{ CS->setStatus(i); cout << endl; }while(i++ < 20); // CS->notify(); }
int main() { ConcreteSubject* sub = new ConcreteSubject(); Observer* o1 = new ConcreteObserverA(sub); Observer* o2 = new ConcreteObserverB(sub); sub->SetState("old"); sub->Notify(); sub->SetState("new"); sub->Notify(); system("pause"); return 0; }
int main(int argc, char * argv[]) { ConcreteSubject * subject = new ConcreteSubject(); ConcreteObserver * observer_1 = new ConcreteObserver(); ConcreteObserver * observer_2 = new ConcreteObserver(); subject->RegisterObserver(observer_1); subject->RegisterObserver(observer_2); subject->NotifyObservers(); system("pause"); return 0; }
int main() { ConcreteObserver* ob1 = new ConcreteObserver("ob1"); ConcreteObserver* ob2 = new ConcreteObserver("ob2"); ConcreteObserver* ob3 = new ConcreteObserver("ob3"); ConcreteSubject* subject = new ConcreteSubject(); subject->attach(ob1); subject->attach(ob2); subject->attach(ob3); subject->set_state(3); return 0; }
int main(int argc, char *argv[]) { ConcreteSubject *sub = new ConcreteSubject(); Observer *obs1 = new ConcreteObserverA(sub); Observer *obs2 = new ConcreteObserverB(sub); sub->SetState("old"); sub->Notify(); sub->SetState("new"); sub->Notify(); delete obs2; delete obs1; delete sub; return 0; }
int main() { // Das Objekt h�lt alle Daten (=notfier = subject) ConcreteSubject* subj = new ConcreteSubject(); ObserverInterface* obs1 = new ConcreteObserver(subj, "A"); ObserverInterface* obs2 = new ConcreteObserver(subj, "B"); // Observer(=views) an Subjekt anh�ngen (attachen) subj->attach(obs1); subj->attach(obs2); // Daten �ndern und Observer informieren (notify) subj->setData("TestData"); subj->notify(); return 0; }
int main() { ConcreteSubject *cs = new ConcreteSubject; Observer *obs[COUNT_OBS]; State s; for (int i = 0; i < COUNT_OBS; i++) obs[i] = new ConcreteObserver(cs); s._state = 1; cs->SetState(s); printstate(obs); cs->Detach(obs[5]); s._state = 4; cs->SetState(s); printstate(obs); cs->Attache(obs[5]); s._state = 2; cs->SetState(s); printstate(obs); return 0; }
int main() { ConcreteSubject product; ConcObs shop1("Shop 1"); ConcObs shop2("Shop 2"); ConcObs shop2("Shop 3"); product.Attach(&shop1); product.Attach(&shop2); product.Attach(&shop3); product.ChangePrice(23.0f); product.Detach(&shop2); product.ChangePrice(26.0f); return 0; }
void update() { observerState = subject->getData(); cout << "Observer " << name << " hat neuen Zustand: " << observerState << endl; }
void Update() { observerState = subject->GetState(); cout << "New state of " << name << " is " << observerState << endl; }