-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfacade.js
More file actions
57 lines (47 loc) · 1.08 KB
/
facade.js
File metadata and controls
57 lines (47 loc) · 1.08 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
49
50
51
52
53
54
55
56
57
/**
* Facade
*
* Facade is a structural design pattern that provides a simplified
* interface to a complex subsystem, making it easier to use.
*/
class Engine {
start() {
console.log('Двигатель запущен')
}
stop() {
console.log('Двигатель остановлен')
}
}
class Lights {
turnOn() {
console.log('Фары включены')
}
turnOff() {
console.log('Фары выключены')
}
}
class CarFacade {
constructor() {
this.engine = new Engine()
this.lights = new Lights()
}
startCar() {
this.engine.start()
this.lights.turnOn()
console.log('Машина готова к движению')
}
stopCar() {
this.lights.turnOff()
this.engine.stop()
console.log('Машина остановлена')
}
}
const car = new CarFacade()
car.startCar()
// Двигатель запущен
// Фары включены
// Машина готова к движению
car.stopCar()
// Фары выключены
// Двигатель остановлен
// Машина остановлена