-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhospital.ts
More file actions
74 lines (62 loc) · 1.49 KB
/
hospital.ts
File metadata and controls
74 lines (62 loc) · 1.49 KB
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
73
74
class HospitalPerson {
protected name: string;
protected id: number;
constructor(name: string, id: number) {
this.name = name;
this.id = id;
}
getDetails(): string {
return `ID: ${this.id}, Name: ${this.name}`;
}
// polymorphic method
getRole(): string {
return `Hospital person`;
}
}
class Doctor extends HospitalPerson {
private specialization: string;
constructor(name: string, id: number, specialization: string) {
super(name, id);
this.specialization = specialization;
}
getRole(): string {
return "Doctor";
}
diagnose(): void {
console.log(`${this.name} is diagnosing patients`);
}
}
class Nurse extends HospitalPerson {
getRole(): string {
return "Nurse";
}
assistDoctor(): void {
console.log(`${this.name} is assisting the doctor`);
}
}
class Patient extends HospitalPerson {
private illness: string;
constructor(name: string, id: number, illness: string) {
super(name, id);
this.illness = illness;
}
getRole(): string {
return "Patient";
}
getIllness(): string {
return this.illness;
}
}
const hospitalPeople: HospitalPerson[] = [
new Doctor("Dr Ramesh", 1, "cardiology"),
new Nurse("Anita", 2),
new Patient("Rahul", 3, "Fever"),
];
hospitalPeople.forEach((person) => {
console.log(person.getDetails());
console.log(person.getRole());
});
const doctor = new Doctor('Dr anusha', 4, 'surgen');
console.log(doctor.getDetails())
console.log(doctor.getRole())
console.log(doctor.diagnose())