Beispiel #1
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()
{
    ConcreteSubject* s = new ConcreteSubject(100);
    s->attach(new ConcreteObserver("20160701",s));
    s->attach(new ConcreteObserver("20160705",s));
    s->setState(200);
    s->notify();
    return 0;
}
Beispiel #3
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;
}