#include <iostream>
#include <string>
using namespace std;
class SchoolGirl
{
protected:
string name;
public:
string GetName()
{
return name;
}
void SetName(string name)
{
this->name=name;
}
};
class InterFace
{
protected:
virtual void GiveDolls()=0;
virtual void GiveFlowers()=0;
virtual void GiveChoolate()=0;
};
class Pursuit : public InterFace
{
private:
SchoolGirl m_mm;
public:
Pursuit(SchoolGirl mm)
{
m_mm=mm;
}
public:
void GiveDolls()
{
cout<<"送"<<m_mm.GetName()<<" 娃娃"<<endl;
}
void GiveChoolate()
{
cout<<"送"<<m_mm.GetName()<<" 巧克力"<<endl;
}
void GiveFlowers()
{
cout<<"送"<<m_mm.GetName()<<" 鲜花"<<endl;
}
};
class Proxy :public InterFace
{
private:
Pursuit* gg;
public:
Proxy(SchoolGirl mm)
{
gg=new Pursuit(mm);
}
~Proxy()
{
delete gg;
}
void GiveDolls()
{
gg->GiveDolls();
}
void GiveChoolate()
{
gg->GiveChoolate();
}
void GiveFlowers()
{
gg->GiveFlowers();
}
};
int main()
{
SchoolGirl mm;
mm.SetName("娇娇");
Proxy daili(mm);
daili.GiveDolls();
daili.GiveChoolate();
daili.GiveFlowers();
}
C++-代理模式
最新推荐文章于 2024-11-09 19:45:52 发布