Advertisement
sdfxs

Untitled

Jun 1st, 2021
1,082
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Dealer {
  2.     private customers: string[];
  3.  
  4.     constructor() {
  5.         this.customers = [];
  6.     }
  7.    
  8.     orderAuto(customer: Customer, auto: string, info: string) {
  9.         const name = customer.getName();
  10.         console.log(`Customer name: ${name}. Order auto is ${auto}`);
  11.         console.log(`Additional info: ${info}`);
  12.         this.addToCustomersList(name);
  13.     }
  14.    
  15.     addToCustomersList(name: string) {
  16.         this.customers.push(name);
  17.     }
  18.    
  19.     getCustomerList() {
  20.         return this.customers;
  21.     }
  22. };
  23.  
  24. class Customer {
  25.     private name: string;
  26.     private dealerMediator: Dealer;
  27.  
  28.     constructor(name: string, dealerMediator: Dealer) {
  29.         this.name = name;
  30.         this.dealerMediator = dealerMediator;
  31.     }
  32.        
  33.     getName() {
  34.         return this.name;
  35.     }
  36.        
  37.     makeOrder(auto: string, info: string) {
  38.         this.dealerMediator.orderAuto(this, auto, info)
  39.     }
  40. };
  41.  
  42. const mediator = new Dealer();
  43.  
  44. const ivan = new Customer('Ivan', mediator);
  45. const anton = new Customer('Anton', mediator);
  46.  
  47. ivan.makeOrder('Tesla', 'With autopilot!');
  48. anton.makeOrder('Audi', 'With parktronik!');
  49.  
  50. console.log(mediator.getCustomerList());
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement