1
+ class BlurayPlayer {
2
+ on ( ) {
3
+ console . log ( 'Bluray player turning on...' ) ;
4
+ }
5
+
6
+ turnOff ( ) {
7
+ console . log ( 'Bluray turning off..' ) ;
8
+ }
9
+
10
+ play ( ) {
11
+ console . log ( 'Playing bluray disc...' ) ;
12
+ }
13
+ }
14
+
15
+ class Amplifier {
16
+ on ( ) {
17
+ console . log ( 'Amp is turning on..' ) ;
18
+ }
19
+
20
+ turnOff ( ) {
21
+ console . log ( 'Amplifier turning off..' ) ;
22
+ }
23
+
24
+ setSource ( source : string ) {
25
+ console . log ( 'Setting source to ' + source ) ;
26
+ }
27
+
28
+ setVolume ( volumeLevel : number ) {
29
+ console . log ( 'Setting volume to ' + volumeLevel ) ;
30
+ }
31
+ }
32
+
33
+ class Lights {
34
+ dim ( ) {
35
+ console . log ( 'Lights are dimming..' ) ;
36
+ }
37
+ }
38
+
39
+ class TV {
40
+ turnOn ( ) {
41
+ console . log ( 'TV turning on..' ) ;
42
+ }
43
+
44
+ turnOff ( ) {
45
+ console . log ( 'TV turning off..' ) ;
46
+ }
47
+ }
48
+
49
+ class PopcornMaker {
50
+ turnOn ( ) {
51
+ console . log ( 'Popcorn maker turning on..' ) ;
52
+ }
53
+
54
+ turnOff ( ) {
55
+ console . log ( 'Popcorn maker turning off..' ) ;
56
+ }
57
+
58
+ pop ( ) {
59
+ console . log ( 'Popping corn!' ) ;
60
+ }
61
+ }
62
+
63
+ // ----
64
+ class HomeTheaterFacade {
65
+ private bluray : BlurayPlayer ;
66
+ private amp : Amplifier ;
67
+ private lights : Lights ;
68
+ private tv : TV ;
69
+ private popcornMaker : PopcornMaker ;
70
+
71
+ constructor ( amp : Amplifier , bluray : BlurayPlayer , lights : Lights , tv : TV , popcornMaker : PopcornMaker ) {
72
+ this . bluray = bluray ;
73
+ this . amp = amp ;
74
+ this . lights = lights ;
75
+ this . tv = tv ;
76
+ this . popcornMaker = popcornMaker ;
77
+ }
78
+
79
+ public watchMovie ( ) {
80
+ this . popcornMaker . turnOn ( ) ;
81
+ this . popcornMaker . pop ( ) ;
82
+
83
+ this . lights . dim ( ) ;
84
+
85
+ this . tv . turnOn ( ) ;
86
+
87
+ this . amp . on ( ) ;
88
+ this . amp . setSource ( 'bluray' ) ;
89
+ this . amp . setVolume ( 11 ) ;
90
+
91
+ this . bluray . on ( ) ;
92
+ this . bluray . play ( ) ;
93
+ }
94
+
95
+ endMovie ( ) {
96
+ this . popcornMaker . turnOff ( ) ;
97
+ this . amp . turnOff ( ) ;
98
+ this . tv . turnOff ( ) ;
99
+ this . bluray . turnOff ( ) ;
100
+ }
101
+ }
102
+
103
+ // ----
104
+ let bluray = new BlurayPlayer ( ) ;
105
+ let amp = new Amplifier ( ) ;
106
+ let lights = new Lights ( ) ;
107
+ let tv = new TV ( ) ;
108
+ let popcornMaker = new PopcornMaker ( ) ;
109
+
110
+ let hometheater = new HomeTheaterFacade ( amp , bluray , lights , tv , popcornMaker ) ;
111
+ hometheater . watchMovie ( ) ;
0 commit comments