Mid GoF Patterns

Real Subject (RealImage):?

  • The RealImage class implements the IImage interface and represents the actual

object that we want to control access to. It contains the logic to load and display the

image.

public class RealImage : IImage

private readonly string _filename;

public RealImage(string filename) => _filename = filename;

public void Display() => Console.WriteLine($"Displaying

{_filename}");

  • Behavior:
  • The RealImage object is only loaded once the Display() method is called.

This behavior can be resource-intensive, especially if the image is large.

More from Design Patterns in C#

All questions for this course