53 lines
866 B
C++
53 lines
866 B
C++
#include <string>
|
|
#include <iostream>
|
|
using namespace std;
|
|
|
|
class Image
|
|
{
|
|
public:
|
|
Image(){}
|
|
virtual ~Image(){}
|
|
virtual void display() = 0;
|
|
};
|
|
|
|
class RealImage : public Image
|
|
{
|
|
public:
|
|
RealImage(string fileName) : fileName(fileName)
|
|
{
|
|
loadFromDisk(fileName);
|
|
}
|
|
void loadFromDisk(string fileName)
|
|
{
|
|
cout << "Loading " + fileName << endl;
|
|
}
|
|
void display()
|
|
{
|
|
cout << "Displaying " + fileName << endl;
|
|
}
|
|
|
|
private:
|
|
string fileName;
|
|
};
|
|
|
|
class ProxyImage : public Image
|
|
{
|
|
public:
|
|
ProxyImage(string fileName) : fileName(fileName)
|
|
{
|
|
realImage = nullptr;
|
|
}
|
|
void display()
|
|
{
|
|
if (realImage == nullptr)
|
|
{
|
|
realImage = new RealImage(fileName);
|
|
}
|
|
realImage->display();
|
|
}
|
|
|
|
private:
|
|
RealImage *realImage;
|
|
string fileName;
|
|
};
|