Skip to content

Commit

Permalink
Added: Structural/Brigde pattern for Typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaganeshrk committed Oct 12, 2022
1 parent f98189f commit a33f204
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Structural/Bridge/typescript/bridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
interface Implementation {
operationImplementation(): string;
}

class Abstraction {
protected implementation: Implementation;

constructor(implementation: Implementation) {
this.implementation = implementation;
}

public operation(): string {
const result = this.implementation.operationImplementation();
return `Abstraction: Base operation with:\n${result}`;
}
}

class ExtendedAbstraction extends Abstraction {
public operation(): string {
const result = this.implementation.operationImplementation();
return `ExtendedAbstraction: Extended operation with:\n${result}`;
}
}

class ConcreteImplementationA implements Implementation {
public operationImplementation(): string {
return "ConcreteImplementationA: Here's the result on the platform A";
}
}

class ConcreteImplementationB implements Implementation {
public operationImplementation(): string {
return "ConcreteImplementationB: Here's the result on the platform B";
}
}

let implementation = new ConcreteImplementationA();
let abstraction = new Abstraction(implementation);

console.log(abstraction.operation());
console.log("");

implementation = new ConcreteImplementationB();
abstraction = new ExtendedAbstraction(implementation);

console.log(abstraction.operation());

0 comments on commit a33f204

Please sign in to comment.