Last active
November 8, 2023 15:42
-
-
Save trikitrok/4b5071c4d5e99ee1088a957f91fff0fe 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
// 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