-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdapter.js
54 lines (44 loc) · 864 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
43
44
45
46
47
48
49
50
51
52
53
54
class Engine2
{
simpleInterface()
{
console.log('Engine 2.0 - tr-tr-tr');
}
}
class EngineV8
{
complecatedInterface()
{
console.log('Engine V8! - wroom wroom!');
}
}
class EngineV8Adapter
{
constructor(engine)
{
this.engine = engine;
}
simpleInterface()
{
this.engine.complecatedInterface();
}
}
class Auto
{
startEngine(engine)
{
engine.simpleInterface();
}
}
//engine 2.0
const myCar = new Auto();
const oldEngine = new Engine2();
myCar.startEngine(oldEngine);
//Engine V8 with adapter
const myCar1 = new Auto();
const engineAdapter = new EngineV8Adapter(new EngineV8());
myCar1.startEngine(engineAdapter);
//Engine V8 without adapter
//const myCar2 = new Auto();
//const engineAdapter1 = new EngineV8();
//myCar2.startEngine(engineAdapter1); error