:代理模式:proxy

时间:2025-03-26 21:08:07

:代理模式:proxy

#ifndef __PROXY_H__
#define __PROXY_H__
class Subject
{
public:
Subject(){}
virtual ~Subject(){}
virtual void request(){}
}; class RealSubject : public Subject
{
public:
RealSubject(){}
virtual ~RealSubject(){}
virtual void request(){}
}; class mProxy : public Subject
{
private:
RealSubject * rs;
public:
mProxy(){}
virtual~mProxy(){}
virtual void request()
{
if (rs == NULL)
{
rs = new RealSubject();
}
rs->request();
}
}; #endif
#include <iostream>
#include "Proxy.h"
using namespace std;
int main()
{
Subject *s = new mProxy();
s->request();
return 0;
}