-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added: Structural/Brigde pattern for Typescript
- Loading branch information
1 parent
f98189f
commit a33f204
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |