-
Notifications
You must be signed in to change notification settings - Fork 4
/
06.computer.js
114 lines (90 loc) · 2.62 KB
/
06.computer.js
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
function generateComputerClasses() {
class PcComponent {
constructor(manufacturer) {
if (new.target === PcComponent) {
throw new Error;
}
this.manufacturer = manufacturer;
}
}
class Keyboard extends PcComponent {
constructor(manufacturer, responseTime) {
super(manufacturer);
this.responseTime = responseTime;
}
}
class Monitor extends PcComponent {
constructor(manufacturer, width, height) {
super(manufacturer);
this.width = width;
this.height = height;
}
}
class Battery extends PcComponent {
constructor(manufacturer, expectedLife) {
super(manufacturer);
this.expectedLife = expectedLife;
}
}
class Computer extends PcComponent {
constructor(manufacturer, processorSpeed, ram, hardDiskSpace) {
if (new.target === Computer) {
throw new Error;
}
super(manufacturer);
this.processorSpeed = processorSpeed;
this.ram = ram;
this.hardDiskSpace = hardDiskSpace;
}
}
class Laptop extends Computer {
constructor(manufacturer, processorSpeed, ram, hardDiskSpace, weight, color, battery) {
super(manufacturer, processorSpeed, ram, hardDiskSpace);
this.weight = weight;
this.color = color;
this.battery = battery;
}
get battery() {
return this._battery;
}
set battery(value) {
if (!(value instanceof Battery)) {
throw new TypeError;
}
this._battery = value;
}
}
class Desktop extends Computer {
constructor(manufacturer, processorSpeed, ram, hardDiskSpace, keyboard, monitor) {
super(manufacturer, processorSpeed, ram, hardDiskSpace);
this.keyboard = keyboard;
this.monitor = monitor;
}
get keyboard() {
return this._keyboard;
}
set keyboard(value) {
if (!(value instanceof Keyboard)) {
throw new TypeError;
}
this._keyboard = value;
}
get monitor() {
return this._monitor;
}
set monitor(value) {
if (!(value instanceof Monitor)) {
throw new TypeError;
}
this._monitor = value;
}
}
return {
Battery,
Keyboard,
Monitor,
Computer,
Laptop,
Desktop
}
}