Proxy (ProxyImage):?
- The ProxyImage class also implements the IImage interface and controls access
to the RealImage. It is responsible for lazy loading the real image only when needed
(i.e., the first time Display() is called).
Follow:
public class ProxyImage : IImage
private readonly string _filename;
private RealImage _realImage;
public ProxyImage(string filename) => _filename = filename;
public void Display()
if (_realImage == null)
_realImage = new RealImage(_filename);
_realImage.Display();
- Behavior:
- The proxy holds a reference to a RealImage and initializes it only when the
Display() method is called for the first time. This delays the loading of the
image, making it more efficient if the Display() method is not called
frequently.