Observer

Example
using namespace std; typedef char* Message; struct Observer { // abstract virtual void notify(Message m) = 0; }; struct Concrete_observer : public Observer { Concrete_observer(char *name) : name(name) {} virtual void notify(Message m) { cout << name << " notified - message: " << m << endl; }    char *name; }; struct Subject { // abstract void register_observer(Observer *o) { observer_collection.push_back(o); }    void unregister_observer(Observer *o) { remove(observer_collection.begin, observer_collection.end, o); }    void notify_observers(Message m); vector observer_collection; }; void Subject::notify_observers(Message m) { for(vector::iterator i = observer_collection.begin;            i != observer_collection.end; ++i) (*i)->notify(m); } class Concrete_subject : public Subject { }; main { Concrete_subject cs; Concrete_observer obs1("obs1"), obs2("obs2"); cs.register_observer(&obs1); cs.register_observer(&obs2); cs.notify_observers("first message"); cs.unregister_observer(&obs1); cs.notify_observers("second message"); }
 * 1) include
 * 2) include
 * 3) include