// Pursuit.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
/**
* 代理模式(Proxy): 为其他对象提供一种代理以控制对这个对象的访问
**/
class SchoolGir
{
private:
string _Name;
public:
SchoolGir(string name = "M")
{
_Name = name;
}
string MM()
{
return _Name;
}
};
class GiveGift
{
public:
virtual void GiveDolls(){};
virtual void GiveFlowers(){};
virtual void GiveChocolate(){};
};
class Pursuite : public GiveGift
{
SchoolGir* _pM;
public:
Pursuite(SchoolGir* mm)
{
_pM = mm;
}
void GiveDolls()
{
cout << _pM->MM().c_str()<<" 送你洋娃娃" << endl;
}
void GiveFlowers()
{
cout << _pM->MM().c_str() << " 送你鲜花" << endl;
}
void GiveChocolate()
{
cout << _pM->MM().c_str() << " 送你巧克力" << endl;
}
};
class Proxy : public GiveGift
{
Pursuite* _pG;
public:
Proxy(SchoolGir* mm)
{
_pG = new Pursuite(mm);
}
void GiveDolls()
{
_pG->GiveDolls();
}
void GiveFlowers()
{
_pG->GiveFlowers();
}
void GiveChocolate()
{
_pG->GiveFlowers();
}
};
int _tmain(int argc, _TCHAR* argv[])
{
SchoolGir* J = new SchoolGir("Jiao");
Proxy * daili = new Proxy(J);
daili->GiveDolls();
daili->GiveFlowers();
daili->GiveChocolate();
return 0;
}
运行结果: