#include<iostream>
using namespace std;
class Girl{
public:
Girl(string n){name = n;};
string getName(){return name;};
private:
string name;
};
class GiveGifts{
public:
virtual void giveFlowers() = 0;
virtual void giveDolls() = 0;
};
class Pursuit : public GiveGifts{
public:
Pursuit(Girl* m) : mm(m){};
void giveFlowers(){cout<<"Give flowers to "<<mm->getName()<<endl;};
void giveDolls(){cout<<"Give dolls to "<<mm->getName()<<endl;};
private:
Girl * mm;
};
class Proxy : public GiveGifts{
public:
Proxy(Girl* mm){gg = new Pursuit(mm);};
void giveFlowers(){gg->giveFlowers();};
void giveDolls(){gg->giveDolls();};
private:
Pursuit * gg;
};
int main(){
Girl * mm = new Girl("Jolly");
Proxy * p = new Proxy(mm);
p->giveFlowers();
p->giveDolls();
return 0;
}
代理模式c++实现
最新推荐文章于 2024-10-31 04:41:10 发布