-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxyPatternDemo.java
More file actions
48 lines (43 loc) · 1.42 KB
/
ProxyPatternDemo.java
File metadata and controls
48 lines (43 loc) · 1.42 KB
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
interface OfficeInternetAccess {
public void grantInternetAccess();
}
class RealInternetAccess implements OfficeInternetAccess {
private String employeeName;
public RealInternetAccess(String empName) {
this.employeeName = empName;
}
@Override
public void grantInternetAccess() {
System.out.println("Internet Access granted for employee: "+ employeeName);
}
}
class ProxyInternetAccess implements OfficeInternetAccess {
private String employeeName;
private RealInternetAccess realaccess;
public ProxyInternetAccess(String employeeName) {
this.employeeName = employeeName;
}
@Override
public void grantInternetAccess()
{
if (getRole(employeeName) > 4)
{
realaccess = new RealInternetAccess(employeeName);
realaccess.grantInternetAccess();
}
else
{
System.out.println("No Internet access granted. Your job level is below 5");
}
}
public int getRole(String emplName) {
return 9;
}
}
public class ProxyPatternDemo{
public static void main(String[] args)
{
OfficeInternetAccess access = new ProxyInternetAccess("XYZ");
access.grantInternetAccess();
}
}