-
Notifications
You must be signed in to change notification settings - Fork 0
/
oop.ts
68 lines (54 loc) · 1.33 KB
/
oop.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//encaptultions
class Account {
private balance: number = 0;
public deposit(amount: number){
this.balance+=amount;
}
withdraw(amount: number){
this.balance-=amount;
}
public getBalance(){
return this.balance;
}
}
const cc = new Account();
cc.deposit(30);
cc.withdraw(40);
console.log(cc.getBalance())
//polymorphism
abstract class UIControl {
public abstract draw();
}
class TextBox extends UIControl{
draw(){
console.log("text box")
}
}
class CheckBox extends UIControl{
draw(){
console.log("check box")
}
}
class CheckingAccount {
open(initialAmount: number) {
console.log("initialAmount- bse clss: ", initialAmount)
}
}
class BusinessCheckingAccount extends CheckingAccount {
open(initialAmount: number) {
if (initialAmount < 1000) {
throw new Error("Business accounts must have an initial deposit of 1.000 Euros")
}
super.open(initialAmount);
}
}
class PersonalCheckingAccount extends CheckingAccount {
open(initialAmount: number) {
if (initialAmount <= 0) {
throw new Error("Personal accounts must have an initial deposit of more than zero Euros")
}
super.open(initialAmount);
}
}
const bc = new BusinessCheckingAccount();
console.log(bc.open(20000));