|
| 1 | +abstract class MoneyTransfer { |
| 2 | + public process(): void { |
| 3 | + this.validateAccounts(); |
| 4 | + this.authorizeTransfer(); |
| 5 | + this.transferFunds(); |
| 6 | + this.notifyParties(); |
| 7 | + } |
| 8 | + |
| 9 | + protected validateAccounts(): void { |
| 10 | + console.log('Validating sender and receiver accounts...'); |
| 11 | + } |
| 12 | + |
| 13 | + protected notifyParties(): void { |
| 14 | + console.log('Notifying sender and receiver of the transaction...'); |
| 15 | + } |
| 16 | + |
| 17 | + protected abstract authorizeTransfer(): void; |
| 18 | + protected abstract transferFunds(): void; |
| 19 | +} |
| 20 | + |
| 21 | +class DomesticTransfer extends MoneyTransfer { |
| 22 | + protected authorizeTransfer(): void { |
| 23 | + console.log('Authorizing domestic transfer...'); |
| 24 | + } |
| 25 | + |
| 26 | + protected transferFunds(): void { |
| 27 | + console.log('Domestic transfer...'); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +class InternationalTransfer extends MoneyTransfer { |
| 32 | + protected authorizeTransfer(): void { |
| 33 | + console.log('Authorizing international transfer...'); |
| 34 | + } |
| 35 | + |
| 36 | + protected transferFunds(): void { |
| 37 | + console.log('International transfer with currency conversion...'); |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +// Usage |
| 42 | + |
| 43 | +console.log('--- DomesticTransfer ---'); |
| 44 | + |
| 45 | +const domesticTransfer = new DomesticTransfer(); |
| 46 | +domesticTransfer.process(); |
| 47 | + |
| 48 | +console.log('--- InternationalTransfer ---'); |
| 49 | + |
| 50 | +const internationalTransfer = new InternationalTransfer(); |
| 51 | +internationalTransfer.process(); |
0 commit comments