Example #1
0
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(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;
}
Example #3
0
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;
}
Example #4
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() {
    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;
}