예제 #1
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;
}
예제 #2
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;
}
예제 #3
0
파일: Main.cpp 프로젝트: lifuxianoa/Mystudy
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;
}
예제 #4
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;
}