-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbridge.js
57 lines (46 loc) · 947 Bytes
/
bridge.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
/**
* Created by betty on 8/7/20.
*/
"use strict";
// decouples an abstraction from its implementation so that the two can vary independently.
// 类似责任单一, 建模, 将抽象与实现分离, 以便两则解偶, 两则虽依赖,但做到解偶
class Printer {
constructor(ink) {
this.ink = ink
}
}
class EpsonPrinter extends Printer {
constructor(ink) {
super(ink);
}
printer() {
return `EpsonPrinter, ink: ${this.ink.get()}`
}
}
class HPPrinter extends Printer {
constructor(ink) {
super(ink);
}
printer() {
return `HPPrinter, ink: ${this.ink.get()}`
}
}
class Ink {
constructor(type) {
this.type = type
}
get() {
return this.type
}
}
class AcrylicInk extends Ink {
constructor() {
super("AcrylicInk");
}
}
class AlcoholInk extends Ink {
constructor() {
super("AlcoholInk");
}
}
module.exports = {EpsonPrinter, HPPrinter, AcrylicInk, AlcoholInk}