-
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.
Merge pull request #447 from sivaganeshrk/Structural/Facade_typescript
Added Structural/Facade Pattern for Typescript
- Loading branch information
Showing
3 changed files
with
50 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
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 @@ | ||
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()); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.