Last active
November 17, 2018 17:14
-
-
Save sangheestyle/793f6b75ecc2cb57d5f9ea8c289b5fe0 to your computer and use it in GitHub Desktop.
Practice the Facade Pattern in typescript
This file contains hidden or 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
import { Facade } from "./facade"; | |
const facade: Facade = new Facade(); | |
const isEligibile: boolean = facade.checkEligibility(); | |
console.log(`You are${isEligibile ? '' : 'not'} eligible.`); |
This file contains hidden or 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
export class BackgroudCheck { | |
criminalRecords(): boolean { | |
return false; | |
} | |
} |
This file contains hidden or 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
import { Funds } from "./funds"; | |
import { BackgroudCheck } from "./backgroudCheck"; | |
import { Fraud } from "./fraud"; | |
export class Facade { | |
private funds: Funds = new Funds(); | |
private backgroundCheck: BackgroudCheck = new BackgroudCheck(); | |
private fraud: Fraud = new Fraud(); | |
checkEligibility(): boolean { | |
return this.funds.checkFunds() && | |
!this.backgroundCheck.criminalRecords() && | |
!this.fraud.checkFraud(); | |
} | |
} |
This file contains hidden or 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
export class Fraud { | |
checkFraud(): boolean { | |
return false; | |
} | |
} |
This file contains hidden or 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
export class Funds { | |
checkFunds(): boolean { | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example from mastering-typescript-programming