-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxy.js
More file actions
40 lines (32 loc) · 808 Bytes
/
Proxy.js
File metadata and controls
40 lines (32 loc) · 808 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
// Proxy is a structural pattern.
// Заместитель - структурный шаблон проектирования.
class NetworkAccess {
connect() {
console.log('Подключение к сети!');
}
disconnect() {
console.log('Отключение от сети!');
}
}
class SecureNetwork {
constructor(network) {
this.network = network;
}
connect(password) {
if (this.authenticate(password)) {
this.network.connect();
} else {
console.log('Доступ запрещён!');
}
}
authenticate(password) {
return password === 'Max';
}
disconnect() {
this.network.disconnect();
}
}
const myNetwork = new SecureNetwork(new NetworkAccess());
myNetwork.connect('Bill');
myNetwork.connect('Max');
myNetwork.disconnect();