C++设计模式之代理
C++设计模式之代理
废话少说,先奉上代码:
#include "stdafx.h"#include <iostream>using namespace std;class IKindwomen{public:IKindwomen(void);~IKindwomen(void);virtual void makeEyesWithMan();virtual void tlaWithMan();};class WangPo{public:WangPo(IKindwomen * pKindwomen);~WangPo();void makeEyesWithMan();void tlaWithMan();private:IKindwomen * pKindwomen;};class PanJianLian:public IKindwomen{public:PanJianLian();~PanJianLian();virtual void makeEyesWithMan();virtual void tlaWithMan();};class JiaShi:public IKindwomen{public:JiaShi();~JiaShi();virtual void makeEyesWithMan();virtual void tlaWithMan();};WangPo::WangPo(IKindwomen * pKindwomen){this->pKindwomen = pKindwomen;}WangPo::~WangPo(){delete this->pKindwomen;}void WangPo::makeEyesWithMan(){this->pKindwomen->makeEyesWithMan();}void WangPo::tlaWithMan(){this->pKindwomen->tlaWithMan();}PanJianLian::PanJianLian(){}PanJianLian::~PanJianLian(){}void PanJianLian::makeEyesWithMan(){cout<<"潘金莲抛媚眼!"<<endl;}void PanJianLian::tlaWithMan(){cout<<"潘金莲谈恋爱!"<<endl;}JiaShi::JiaShi(){}JiaShi::~JiaShi(){}void JiaShi::makeEyesWithMan(){cout<<"贾氏抛媚眼!"<<endl;}void JiaShi::tlaWithMan(){cout<<"贾氏谈恋爱!"<<endl;}int _tmain(int argc, _TCHAR* argv[]){WangPo* wangPo = new WangPo(new PanJianLian());wangPo->makeEyesWithMan();wangPo->tlaWithMan();delete wangPo;return 0;}