-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path12-6-Employee2.js
81 lines (71 loc) Β· 1.52 KB
/
12-6-Employee2.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
/**
* p492 μμ
*/
class Employee {
#name;
#type;
constructor(name, type) {
this.validateType(type);
this.#name = name;
this.#type = Employee.createEmployeeType(type);
}
validateType(arg) {
if (!["engineer", "manager", "salesperson"].includes(arg)) {
throw new Error(`${arg}λΌλ μ§μ μ νμ μμ΅λλ€.`);
}
}
get typeString() {
return this.#type.toString();
}
get type() {
return this.#type;
}
set type(arg) {
this.#type = Employee.createEmployeeType(arg);
}
static createEmployeeType(aString) {
switch (aString) {
case "engineer":
return new Engineer();
case "manager":
return new Manager();
case "salesperson":
return new Salesperson();
default:
throw new Error(`${aString}λΌλ μ§μ μ νμ μμ΅λλ€.`);
}
}
toString() {
return `${this.#name} (${this.type.capitalizedType})`;
}
}
class EmployeeType {
get capitalizedType() {
return (
this.toString().charAt(0).toUpperCase() +
this.toString().substr(1).toLowerCase()
);
}
}
class Engineer extends EmployeeType {
toString() {
return "engineer";
}
}
class Manager extends EmployeeType {
toString() {
return "manager";
}
}
class Salesperson extends EmployeeType {
toString() {
return "salesperson";
}
}
/**
* μμ μ€νμ μν μμμ μ½λ
*/
const name = "λ§ν΄ νμΈλ¬";
const type = "engineer";
const employee = new Employee(name, type);
console.log(employee.toString());