-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathChain.ts
52 lines (36 loc) · 1.22 KB
/
Chain.ts
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
export interface SaleHandler {
setNext(handler: SaleHandler): void
handle(amount: number): void
}
export abstract class AbstractSaleHandler implements SaleHandler {
private nextHandler!: SaleHandler
setNext(handler: SaleHandler): void {
this.nextHandler = handler
}
handle(amount : number): void {
if(this.nextHandler) this.nextHandler.handle(amount)
}
}
export class Salesman extends AbstractSaleHandler {
handle(amount: number): void {
if(amount < 1000) console.log(`${amount}$: A Salesman will handle this order`)
else super.handle(amount)
}
}
export class SalesLeader extends AbstractSaleHandler {
handle(amount: number): void {
if(amount < 10000) console.log(`${amount}$: A Sales Leader will handle this order`)
else super.handle(amount)
}
}
export class SalesManager extends AbstractSaleHandler {
handle(amount: number): void {
if(amount < 50000) console.log(`${amount}$: A Sales Manager will handle this order`)
else super.handle(amount)
}
}
export class SalesOfficer extends AbstractSaleHandler {
handle(amount: number): void {
console.log(`${amount}$: A Sales Officer will handle this order`)
}
}