???????????????????????????????????????????????????????????????????????????????????????????????????“Define a one-to-many dependency between objects so that when one object changes state?? all its dependents are notified and updated automatically.” – GoF
????UML?
???????
????1.????????????????????????????
????2.??????????????????????????????1?????
????3.????????????????????????????????????????????????????????????????????
????4.?ж?????????????????????????????
????C++???

 

Observer.h
/*
??????????????????????????????????????????????????????
??????????????????????????????????
*/
#include <iostream>
#include <vector>
using namespace std;
class Observer;
//Account?????????????
class Account
{
protected:
vector<Observer*> observer;
double balance;
public:
virtual void add_observer(Observer *o)=0;
virtual void remove_observer(Observer *o)=0;
virtual void notify_observer()=0;
virtual void set_balance(double balance)=0;
virtual double get_balance()=0;
public:
virtual ~Account()
{
cout<<"in the destructor of Account"<<endl;
}
};