Skip to content

Commit

Permalink
Merge pull request #447 from sivaganeshrk/Structural/Facade_typescript
Browse files Browse the repository at this point in the history
Added Structural/Facade Pattern for Typescript
  • Loading branch information
ZoranPandovski authored Oct 13, 2022
2 parents 7bbe09a + ad704aa commit d533d53
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Structural/Facade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ of external code on the inner parts of a library, because the most part of the c

The facade design pattern uses the interface methods to delegate functions to the more complex methods that are part of the system
implementation, which remain hidden for outside code (normally the client code).

## STRUCTURE

<img src="../../media/facade.png" alt="Facade patterns">
46 changes: 46 additions & 0 deletions Structural/Facade/typescript/facade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class Facade {
protected subsystem1: Subsystem1;

protected subsystem2: Subsystem2;

constructor(subsystem1?: Subsystem1, subsystem2?: Subsystem2) {
this.subsystem1 = subsystem1 || new Subsystem1();
this.subsystem2 = subsystem2 || new Subsystem2();
}

public operation(): string {
let result = "Facade initializes subsystems:\n";
result += this.subsystem1.operation1();
result += this.subsystem2.operation1();
result += "Facade orders subsystems to perform the action:\n";
result += this.subsystem1.operationN();
result += this.subsystem2.operationZ();

return result;
}
}

class Subsystem1 {
public operation1(): string {
return "Subsystem1: Ready!\n";
}

public operationN(): string {
return "Subsystem1: Go!\n";
}
}

class Subsystem2 {
public operation1(): string {
return "Subsystem2: Get ready!\n";
}

public operationZ(): string {
return "Subsystem2: Fire!";
}
}

const subsystem1 = new Subsystem1();
const subsystem2 = new Subsystem2();
const facade = new Facade(subsystem1, subsystem2);
console.log(facade.operation());
Binary file added media/facade.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d533d53

Please sign in to comment.