Skip to content

Commit a12854f

Browse files
committed
Add TypeScrtipt example
1 parent 790a11b commit a12854f

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

‎TypeScript/1-theory.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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

Comments
 (0)