代理模式
访问对象时引入一定程度的间接性,因为这种间接性,可以附加多种用途。
#include<stdio.h>
#include<string.h>
class Interface
{
public:
virtual void Result()=0;
};
class RealSubject:public Interface
{
public:
void Result()
{
printf("-----true-----\r\n");
}
};
class Proxy:public Interface
{
RealSubject * real;
public:
void Result()
{
real = new RealSubject();
real -> Result();
delete real;
}
};
int main()
{
Proxy * proxy = new Proxy();
proxy -> Result();
delete proxy;
}
UML图: