-
Notifications
You must be signed in to change notification settings - Fork 0
/
typescript.ts
38 lines (29 loc) · 948 Bytes
/
typescript.ts
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
// Bridge: Desacopla una abstracción de su implementación.
interface Implementation {
operation(): string;
}
class ConcreteImplementationA implements Implementation {
operation(): string {
return "ImplementationA Operation";
}
}
class ConcreteImplementationB implements Implementation {
operation(): string {
return "ImplementationB Operation";
}
}
class Abstraction {
protected implementation: Implementation;
constructor(implementation: Implementation) {
this.implementation = implementation;
}
operation(): string {
return this.implementation.operation();
}
}
const implementationA = new ConcreteImplementationA();
const abstractionA = new Abstraction(implementationA);
const implementationB = new ConcreteImplementationB();
const abstractionB = new Abstraction(implementationB);
console.log(abstractionA.operation()); // ImplementationA Operation
console.log(abstractionB.operation()); // ImplementationB Operation