-
Notifications
You must be signed in to change notification settings - Fork 0
/
Proxy.cs
74 lines (61 loc) · 1.59 KB
/
Proxy.cs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
public class SubjectAccesor
{
public interface ISubject
{
string Request();
}
private class Subject
{
public string Request()
{
return "Subject Request" + "Choose left door \n";
}
}
public class Proxy : ISubject
{
Subject subject;
public string Request()
{
if(subject == null)
{
subject = new Subject();
}
return "Proxy: Call to " + subject.Request();
}
}
public class ProtectionProxy : ISubject
{
Subject subject;
string password = "abc";
public string Authenticate (string supplied)
{
if(supplied != password)
return "Protection Proxy: No acess";
else
subject = new Subject();
return "Prot Proxy : Authenticated";
}
public string Request()
{
if(subject==null)
{
return "Protection Proxy: Auth first";
} else
{
return "Protextion Proxy: Call to " +
subject.Request();
}
}
}
public static void Main()
{
ISubject subject = new Proxy();
Console.WriteLine(subject.Request());
ProtectionProxy subject2 = new ProtectionProxy();
Console.WriteLine(subject2.Request());
Console.WriteLine((subject2 as ProtectionProxy).Authenticate("ac"));
Console.WriteLine((subject2 as ProtectionProxy).Authenticate("abc"));
Console.WriteLine(subject2.Request());
}
}