Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface IAccessRequired {
- open(): void;
- close(): void;
- }
- class CarAccess {
- open() {
- console.log('Open')
- }
- close() {
- console.log('Close')
- }
- };
- class SecuritySystem {
- private door: IAccessRequired;
- constructor(door: IAccessRequired) {
- this.door = door;
- }
- open(password: string) {
- if (this.authenticate(password)) {
- this.door.open();
- } else {
- console.log('Доступ запрещён!');
- }
- }
- authenticate(password: string) {
- return password === 'йцукен123';
- }
- close() {
- this.door.close()
- }
- };
- const door = new SecuritySystem(new CarAccess());
- door.open('фыва123');
- door.open('йцукен123');
- door.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement