-
Notifications
You must be signed in to change notification settings - Fork 0
/
oop.vehicle.ts
72 lines (62 loc) · 1.3 KB
/
oop.vehicle.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
69
70
71
72
{
class Vehicle {
constructor(tires: number, fuel: number) {
console.log(tires, fuel);
}
start = () => {
console.log("start");
};
stop = () => {
console.log("stop");
};
run = () => {
console.log("keep going...");
};
}
class Car extends Vehicle {
constructor(
private tires: number,
private fuel: number,
private owner: string
) {
super(tires, fuel);
}
get spec() {
return {
tires: this.tires,
fuel: this.fuel,
owner: this.owner,
};
}
get ownerName() {
return this.owner;
}
set ownerName(newName: string) {
this.owner = newName;
}
}
class Motorcycle extends Vehicle {
// ...
}
class PorcheBoxter extends Car {
run = () => {
console.log("full accelerator!");
};
boost = () => {
// ...
};
}
class HyundaiSonata extends Car {
run = () => {
console.log("please, keep going...");
};
callEngineer = () => {
// ...
};
}
const myPorche = new PorcheBoxter(4, 58, "steve");
console.log(myPorche.start()); // start
console.log(myPorche.ownerName); // steve
console.log(myPorche.spec); // { tires: 4, fuel: 58, owner: 'steve' }
console.log(myPorche.run()); // full accelerator!
}