Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Dealer {
- private customers: string[];
- constructor() {
- this.customers = [];
- }
- orderAuto(customer: Customer, auto: string, info: string) {
- const name = customer.getName();
- console.log(`Customer name: ${name}. Order auto is ${auto}`);
- console.log(`Additional info: ${info}`);
- this.addToCustomersList(name);
- }
- addToCustomersList(name: string) {
- this.customers.push(name);
- }
- getCustomerList() {
- return this.customers;
- }
- };
- class Customer {
- private name: string;
- private dealerMediator: Dealer;
- constructor(name: string, dealerMediator: Dealer) {
- this.name = name;
- this.dealerMediator = dealerMediator;
- }
- getName() {
- return this.name;
- }
- makeOrder(auto: string, info: string) {
- this.dealerMediator.orderAuto(this, auto, info)
- }
- };
- const mediator = new Dealer();
- const ivan = new Customer('Ivan', mediator);
- const anton = new Customer('Anton', mediator);
- ivan.makeOrder('Tesla', 'With autopilot!');
- anton.makeOrder('Audi', 'With parktronik!');
- console.log(mediator.getCustomerList());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement