Skip to content

Instantly share code, notes, and snippets.

@axel-andrade
Last active October 25, 2022 22:03
Show Gist options
  • Save axel-andrade/9337dea3a88a0a4dd0fc91d6f6ab75c1 to your computer and use it in GitHub Desktop.
Save axel-andrade/9337dea3a88a0a4dd0fc91d6f6ab75c1 to your computer and use it in GitHub Desktop.
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