?????????c++???
???????????? ???????[ 2014/6/20 11:39:38 ] ????????c++ net
???????????????????????????????????????????????????????????????????????????????????????????????????“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;
}
};
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11