Skip to content

Instantly share code, notes, and snippets.

@sangheestyle
Last active November 17, 2018 17:14
Show Gist options
  • Save sangheestyle/793f6b75ecc2cb57d5f9ea8c289b5fe0 to your computer and use it in GitHub Desktop.
Save sangheestyle/793f6b75ecc2cb57d5f9ea8c289b5fe0 to your computer and use it in GitHub Desktop.
Practice the Facade Pattern in typescript
import { Facade } from "./facade";
const facade: Facade = new Facade();
const isEligibile: boolean = facade.checkEligibility();
console.log(`You are${isEligibile ? '' : 'not'} eligible.`);
export class BackgroudCheck {
criminalRecords(): boolean {
return false;
}
}
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();
}
}
export class Fraud {
checkFraud(): boolean {
return false;
}
}
export class Funds {
checkFunds(): boolean {
return true;
}
}
@sangheestyle
Copy link
Author

Example from mastering-typescript-programming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment