template< class T > class model {\fbox{model}
public: void tell(view* v) { dependent = v; } one view only
void changed() { if (dependent) dependent->update(); } virtual T value()=0; protected: view* dependent; model() { dependent = 0; } restricted creation
};
template< class T > class view {\fbox{view}
public: view(model* p) { p->tell(this); m = p; } virtual void update() { cout << m->value() << endl; or whatever
} protected: model* m; };
class account : public model{ int n; public: account() { n = 0; } void operator++() { n++; changed(); } int value() { return n; } };
account
account a; viewv(&a); a++; a++;