File tree 5 files changed +50
-2
lines changed
5 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,10 @@ npm install
29
29
npm start
30
30
```
31
31
32
+ ## Reference
33
+
34
+ https://sourcemaking.com/design_patterns
35
+
32
36
## Abstract Factory
33
37
34
38
## Factory Method
Original file line number Diff line number Diff line change 8
8
"license" : " MIT" ,
9
9
"scripts" : {
10
10
"start" : " tsc-watch --onSuccess \" node dist/index.js\" " ,
11
+ "start:abstract-factory" : " tsc-watch --onSuccess \" node dist/index.js\" " ,
11
12
"test" : " jest --watch"
12
13
},
13
14
"dependencies" : {
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Book Factory
3
+ */
4
+ abstract class AbstractBookFactory {
5
+ abstract createJSBook ( ) : AbstractJSBook ;
6
+ // abstract createTSBook(): AbstractTSBook;
7
+ }
8
+
9
+ class QvilBookFactory extends AbstractBookFactory {
10
+ createJSBook ( ) {
11
+ return new AbstractJSBook ( ) ; // error TS2511: Cannot create an instance of an abstract class.
12
+ }
13
+ createTSBook ( ) {
14
+ return "ts" ;
15
+ }
16
+ }
17
+
18
+ /**
19
+ * Book
20
+ */
21
+ abstract class AbstractBook {
22
+ abstract getAuthor ( ) : string ;
23
+ abstract getTitle ( ) : string ;
24
+ }
25
+ abstract class AbstractJSBook extends AbstractBook {
26
+ // constructor(value: string) {
27
+ // super();
28
+ // console.log(value);
29
+ // }
30
+
31
+ getTitle ( ) {
32
+ return this . title ;
33
+ }
34
+
35
+ private title = "Javscript" ;
36
+ }
Original file line number Diff line number Diff line change
1
+ import book from "./book-store" ;
2
+
3
+ console . log ( book ) ;
Original file line number Diff line number Diff line change 1
- import { sum } from "./closure/ScopeChain" ;
1
+ // import { sum } from "./closure/ScopeChain";
2
2
3
- console . log ( sum ( 1 ) ( 2 ) ( 3 ) ( 4 ) ) ;
3
+ // console.log(sum(1)(2)(3)(4));
4
+
5
+ import bookStore from "./abstract-factory/book-store" ;
6
+
7
+ console . log ( bookStore ( ) ) ;
You can’t perform that action at this time.
0 commit comments