-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathadapter.js
42 lines (33 loc) · 861 Bytes
/
adapter.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
/**
* Created by betty on 8/6/20.
*/
"use strict";
// Converts one interface to another so that it matches what the client is expecting
// allows classes with incompatible interfaces to work together by wrapping its own interface around that of an already existing class.
// 封装一个新的类成一个原有的类, 以便兼容
function insertSquareUsbInComputer(computer) {
computer.insertInSquarePort()
}
class Mac {
constructor() {
}
insertInSquarePort() {
console.log("mac insertInSquarePort")
}
}
class Window {
constructor() {
}
insertInCirclePort() {
console.log("window insertInCirclePort")
}
}
class WindowAdapter {
constructor(window) {
this.window = window
}
insertInSquarePort() {
this.window.insertInCirclePort()
}
}
module.exports = {Mac, Window, WindowAdapter, insertSquareUsbInComputer}