-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
55 lines (44 loc) · 1020 Bytes
/
Program.cs
File metadata and controls
55 lines (44 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
namespace Proxy;
public interface IImage
{
void Display();
}
public class RealImage(string fileName) : IImage
{
public string FileName { get; } = fileName;
private void LoadFromDisk()
{
Console.WriteLine($"Loading {FileName} from disk...");
}
public void Display()
{
Console.WriteLine($"Displaying {FileName}");
}
}
public class ImageProxy(string fileName) : IImage
{
private RealImage? realImage;
public void Display()
{
realImage ??= new RealImage(fileName);
realImage.Display();
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("=== Proxy Pattern Demo ===");
Console.WriteLine();
IImage image = new ImageProxy("diagram.png");
Console.WriteLine("First call will load the image:");
image.Display();
Console.WriteLine();
Console.WriteLine("Second call uses cached image:");
image.Display();
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}