C++?????????
???????????? ???????[ 2014/9/22 10:49:28 ] ??????????????? Net C++
???????????????????????????????????????????仯??????????????仯????Windows????о??????????????????????Windows?????????????????????????????????????????????????????????????????е??????????????????????????????????£?
????1????д???????????????????????????????£?
????1.1??????????????Observer???У???????д?麯??update()
????1.2?????????????????Observable?????????addObserver()???????????????????
???????????£?
#ifndef__OBSERVER_H
#define__OBSERVER_H
#include<vector>
#include<algorithm>
#include<string>
#include"YtEvent.h"
classObservable;
classObserver
{
public:
virtualvoidupdate(Observable*from??YtEvent*e)=0;
};
classObservable
{
private:
std::vector<Observer*>_observers;
public:
Observable(){}
virtual~Observable()
{
_observers.clear();
}
//AdditionofObserver
voidaddObserver(Observer*ob)
{
if(std::find(_observers.begin()??_observers.end()??ob)==_observers.end())
{
_observers.push_back(ob);
}
}
//DeletionofObserver
voiddeleteObserver(constObserver*ob)
{
std::vector<Observer*>::iteratori=std::find(_observers.begin()??_observers.end()??ob);
if(i!=_observers.end())
{
_observers.erase(i);
}
}
//ItnotifiesObserver
voidnotifyObservers(YtEvent*e=NULL)
{
std::vector<Observer*>::reverse_iteratori=_observers.rbegin();
while(i!=_observers.rend())
{
(*i++)->update(this??e);
}
}
intcountObservers()const
{
return(int)_observers.size();
}
};
#endif//__OBSERVER_H
??????
???·???
??????????????????
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