-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample10.ts
More file actions
61 lines (52 loc) · 1.96 KB
/
example10.ts
File metadata and controls
61 lines (52 loc) · 1.96 KB
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
56
57
58
59
60
61
// Підсистема керування товарами
class InventoryService {
reserveProduct(productId: string): void {
console.log(`🔄 Резервування товару ${productId}`);
}
releaseProduct(productId: string): void {
console.log(`❌ Скасування резерву товару ${productId}`);
}
}
// Підсистема обробки платежів
class PaymentService {
processPayment(account: string, amount: number): boolean {
console.log(`💳 Проведення платежу ${amount} з рахунку ${account}`);
return true;
}
}
// Підсистема логістики
class ShippingService {
arrangeDelivery(productId: string): void {
console.log(`📦 Організація доставки для товару ${productId}`);
}
}
// Підфасад для оформлення замовлення
class OrderProcessor {
constructor(
private inventory: InventoryService,
private payment: PaymentService,
private shipping: ShippingService
) { }
processOrder(productId: string, account: string, amount: number): void {
this.inventory.reserveProduct(productId);
const success = this.payment.processPayment(account, amount);
if (success) {
this.shipping.arrangeDelivery(productId);
} else {
this.inventory.releaseProduct(productId);
}
}
}
// Центральний фасад
class ShopFacade {
private inventory = new InventoryService();
private payment = new PaymentService();
private shipping = new ShippingService();
private processor = new OrderProcessor(this.inventory, this.payment, this.shipping);
order(productId: string, account: string, amount: number): void {
this.processor.processOrder(productId, account, amount);
}
}
// Клієнтський код
const shop = new ShopFacade();
shop.order("product-42", "user-acc", 299);