@@ -15,19 +15,43 @@ class Department {
15
15
// this.id = '2'; // readonly์ด๊ธฐ ๋๋ฌธ์ error๊ฐ ๋ฐ์ํ๋ค.
16
16
this . employees . push ( employee ) ;
17
17
}
18
+
19
+ printEmployeeInformation ( ) {
20
+ console . log ( this . employees . length ) ;
21
+ console . log ( this . employees ) ;
22
+ }
18
23
}
19
24
20
25
class ITDepartment extends Department {
21
26
admins : string [ ] ;
22
- constructor ( id : string , public admin : string [ ] ) {
27
+ constructor ( id : string , admins : string [ ] ) {
23
28
super ( id , 'IT' ) ;
24
- this . admins = admin ;
29
+ this . admins = admins ;
25
30
}
26
31
}
27
32
28
33
class AccountingDepartment extends Department {
34
+ private lastReport : string ;
35
+
36
+ get mostRecentReport ( ) {
37
+ if ( this . lastReport ) {
38
+ return this . lastReport ;
39
+ }
40
+ throw new Error ( 'No report found.' ) ;
41
+ }
42
+
43
+ set setMostRecentReport ( value : string ) {
44
+ if ( ! value ) {
45
+ throw new Error ( 'Please pass in a valid value!' )
46
+ }
47
+ this . addReport ( value ) ;
48
+ this . lastReport = value ; // ์ฌ๊ธฐ์ lastReport๋ฅผ ์
๋ฐ์ดํธ ๊ทธ๋์ผ lastReport๊ฐ ๋น์ด์์ง ์๊ธฐ ๋๋ฌธ์ ์ ์์ ์ผ๋ก ๋์์ ํ๋ค.
49
+ }
50
+
29
51
constructor ( id : string , private reports : string [ ] ) {
30
52
super ( id , 'Account' ) ;
53
+ //strictPropertyInitialization ํ์ฑํ๋ก ์ด๊ธฐํ ํด์ค์ผ ํจ.
54
+ this . lastReport = reports [ 0 ] || "" ; // ์ด๊ธฐ๊ฐ์ ํ ๋น (reports๊ฐ ๋น์ด์์ผ๋ฉด ๋น ๋ฌธ์์ด)
31
55
}
32
56
33
57
addReport ( text : string ) {
@@ -38,7 +62,6 @@ class AccountingDepartment extends Department {
38
62
console . log ( this . reports ) ;
39
63
}
40
64
}
41
-
42
65
const accounting = new Department ( '1' , 'Accounting' ) ;
43
66
const ITaccounting = new ITDepartment ( '2' , [ 'Max' ] ) ;
44
67
@@ -51,6 +74,10 @@ ITaccounting.printEmployeeInformation();
51
74
52
75
const NewAccounting = new AccountingDepartment ( 'd2' , [ ] ) ;
53
76
77
+ // console.log(NewAccounting.mostRecentReport); //report๊ฐ ์ถ๊ฐ๋์ง ์์์ Error
78
+ NewAccounting . setMostRecentReport = 'Year End Report' ;
54
79
NewAccounting . addReport ( 'Something went wrong...' ) ;
55
80
81
+ console . log ( NewAccounting . mostRecentReport ) ; //report๊ฐ ์์ด์ ๋ฌธ์ ์์ด ์ถ๋ ฅ
82
+
56
83
NewAccounting . printReports ( ) ;
0 commit comments