Skip to content

Commit 076eea6

Browse files
committed
🚧 Abstract Factory Pattern
1 parent fef5bdf commit 076eea6

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
[Javascript Design Pattern](https://www.dofactory.com/javascript/design-patterns)
66

7+
[Learning JavaScript Design Patterns](https://addyosmani.com/resources/essentialjsdesignpatterns/book/)
8+
79
## Types of Design Patterns
810

911
- [Creational](#creational)

TODO.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
* [ ] 多态
2-
* [ ] bind/call/apply 的实现
3-
* [ ] Javascript 原生方法的实现
4-
* [ ] 使用小网页的方式来实现设计模式
5-
* [ ] 抽象 log helper
6-
* [ ] 设计原则
7-
* [ ] 使用 Chain of Responsibility Pattern 和 State Pattern 两种模式来写红绿灯变化
1+
- [ ] 多态
2+
- [ ] bind/call/apply 的实现
3+
- [ ] Javascript 原生方法的实现
4+
- [ ] 使用小网页的方式来实现设计模式
5+
- [ ] 抽象 log helper
6+
- [ ] 设计原则
7+
- [ ] doc.md
8+
- [ ] 使用 Chain of Responsibility Pattern 和 State Pattern 两种模式来写红绿灯变化
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function droidProducer(kind) {
2+
if (kind === 'battle') return battleDroidFactory
3+
return pilotDroidFactory
4+
}
5+
6+
function battleDroidFactory() {
7+
return new B1()
8+
}
9+
10+
function pilotDroidFactory() {
11+
return new Rx24()
12+
}
13+
14+
class B1 {
15+
info() {
16+
return 'B1, Battle Droid'
17+
}
18+
}
19+
20+
class Rx24 {
21+
info() {
22+
return 'Rx24, Pilot Droid'
23+
}
24+
}
25+
26+
export default droidProducer

0 commit comments

Comments
 (0)