-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMediator.js
55 lines (44 loc) · 1.04 KB
/
Mediator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class OfficialDealer
{
constructor()
{
this.customers = [];
}
orderAuto(customer, auto, info)
{
const name = customer.getName();
console.log(`Ordeer name ${name}. Order auto is ${auto}`);
console.log(`Additional info : ${info}`);
this.addToCustomersList(name);
}
addToCustomersList(name)
{
this.customers.push(name);
}
getCustomersList()
{
return this.customers;
}
}
class Customer
{
constructor(name, dealerMediator)
{
this.name = name;
this.dealerMediator = dealerMediator;
}
getName()
{
return this.name;
}
makeOrder(auto, info)
{
this.dealerMediator.orderAuto(this, auto, info);
}
}
const mediator = new OfficialDealer();
const yauhen = new Customer('Yauhen', mediator);
const valera = new Customer('Valera', mediator);
yauhen.makeOrder('Tesla','With autopilot');
valera.makeOrder('Audi','With parktronik');
console.log(mediator.getCustomersList());