Beispiel #1
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;
}