Advertisement
sdfxs

Untitled

May 12th, 2021
929
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. interface IAccessRequired {
  2.     open(): void;
  3.     close(): void;
  4. }
  5.  
  6. class CarAccess {
  7.     open() {
  8.         console.log('Open')
  9.     }
  10.  
  11.     close() {
  12.         console.log('Close')
  13.     }
  14. };
  15.  
  16. class SecuritySystem {
  17.     private door: IAccessRequired;
  18.     constructor(door: IAccessRequired) {
  19.         this.door = door;
  20.     }
  21.  
  22.     open(password: string) {
  23.         if (this.authenticate(password)) {
  24.             this.door.open();
  25.         } else {
  26.             console.log('Доступ запрещён!');
  27.         }
  28.     }
  29.  
  30.     authenticate(password: string) {
  31.         return password === 'йцукен123';
  32.     }
  33.  
  34.     close() {
  35.         this.door.close()
  36.     }
  37. };
  38.  
  39. const door = new SecuritySystem(new CarAccess());
  40.  
  41. door.open('фыва123');
  42. door.open('йцукен123');
  43.  
  44. door.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement