// Proxy. cpp: defines the entry point of the console application.
//
# Include "stdafx. H"
# Include <iostream>
Using namespace STD;
Class subject
{
Public:
Subject ()
{}
Virtual ~ Subject ()
{}
Virtual void request () = 0;
};
Class realsubject: public subject
{
Public:
Realsubject ()
{
Cout <"Construction of realsubject" <Endl;
}
Virtual ~ Realsubject ()
{
Cout <"deconstruction of realsubject" <Endl;
}
Void request ()
{
Cout <"-------------------------------------" <Endl;
}
};
Class Proxy: public subject
{
Public:
Proxy (): RS (null)
{
Cout <"Construction of proxy for realsubject" <Endl;
}
Virtual ~ Proxy ()
{
Delete RS;
Rs = NULL;
}
Void request ()
{
If (null = RS)
{
Cout <"Create a New realsubject and reaquest" <Endl;
Rs = new realsubject ();
}
Else
{
Cout <"The realsubject has been created" <Endl;
}
RS-> request ();
}
PRIVATE:
Realsubject * RS;
};
Int _ tmain (INT argc, _ tchar * argv [])
{
Subject * pproxy = new proxy ();
Pproxy-> request ();
Pproxy-> request ();
Delete pproxy;
Return 0;
}