#include "stdafx.h"
#include <iostream>
using namespace std;
class Subject
{
public:
virtual void display() = 0;
};
class ConcreteSubject:public Subject
{
public:
void display() {cout<<"this is the fucking..."<<endl;}
};
class Proxy:public Subject
{
public:
Proxy():m_pSubject(0) {}
void display()
{
if(m_pSubject == NULL)
{
m_pSubject = new ConcreteSubject;
}
m_pSubject->display();
}
~Proxy() {delete m_pSubject;}
private:
Subject* m_pSubject;
};
int _tmain(int argc, _TCHAR* argv[])
{
Proxy* pProxy = new Proxy();
pProxy->display();
getchar();
return 0;
}
#include <iostream>
using namespace std;
class Subject
{
public:
virtual void display() = 0;
};
class ConcreteSubject:public Subject
{
public:
void display() {cout<<"this is the fucking..."<<endl;}
};
class Proxy:public Subject
{
public:
Proxy():m_pSubject(0) {}
void display()
{
if(m_pSubject == NULL)
{
m_pSubject = new ConcreteSubject;
}
m_pSubject->display();
}
~Proxy() {delete m_pSubject;}
private:
Subject* m_pSubject;
};
int _tmain(int argc, _TCHAR* argv[])
{
Proxy* pProxy = new Proxy();
pProxy->display();
getchar();
return 0;
}