Last active
October 25, 2022 22:03
-
-
Save axel-andrade/9337dea3a88a0a4dd0fc91d6f6ab75c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Employee { | |
private name: string; | |
constructor(name: string) { | |
this.name = name; | |
} | |
public getName(): string { | |
return this.name; | |
} | |
public abstract getSalary(): number; | |
public abstract getCommission(): number; | |
} | |
class WaiterEmployee extends Employee { | |
private salary: number; | |
private salesAmount: number; | |
constructor(name: string, salary: number, salesAmount: number) { | |
super(name); | |
this.salary = salary; | |
this.salesAmount = salesAmount; | |
} | |
// @override | |
public getCommission(): number { | |
return this.salesAmount * 0.2; | |
} | |
// @override | |
public getSalary(): number { | |
return this.salary + this.getCommission(); | |
} | |
// ...other methods here | |
} | |
class SecurityEmployee extends Employee { | |
private salary: number; | |
constructor(name: string, salary: number) { | |
super(name); | |
this.salary = salary; | |
} | |
// @override | |
public getCommission(): number { | |
return 0; | |
} | |
// @override | |
public getSalary() { | |
return this.salary; | |
} | |
// ...other methods here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment