Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Last active November 8, 2023 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trikitrok/4b5071c4d5e99ee1088a957f91fff0fe to your computer and use it in GitHub Desktop.
Save trikitrok/4b5071c4d5e99ee1088a957f91fff0fe to your computer and use it in GitHub Desktop.
// From Code Smells – Part II, Ana Nogal https://www.ananogal.com/blog/code-smells-part-two/
class EmployeeType {
static Worker = new EmployeeType("Worker")
static Supervisor = new EmployeeType("Supervisor")
static Manager = new EmployeeType("Manager")
constructor(type) {
this.type = type
}
}
class Employee {
constructor(salary, bonusPercentage, employeeType) {
this.salary = salary;
this.bonusPercentage = bonusPercentage;
this.employeeType = employeeType;
}
calculateSalary() {
switch (this.employeeType) {
case EmployeeType.Worker:
return this.salary;
case EmployeeType.Supervisor:
return this.salary + (this.bonusPercentage * 0.5);
case EmployeeType.Manager:
return this.salary + (this.bonusPercentage * 0.7);
}
return 0.0;
}
calculateYearBonus() {
switch (this.employeeType) {
case EmployeeType.Worker:
return 0;
case EmployeeType.Supervisor:
return this.salary + this.salary * 0.7;
case EmployeeType.Manager:
return this.salary + this.salary * 10.0;
}
return 0.0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment