Last active
January 6, 2016 02:42
-
-
Save up1/b84d756ac75738677dac to your computer and use it in GitHub Desktop.
When to refactoring
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
public class BonusCalculator { | |
public double getBonus(Employee employee) { | |
if( employee.department == Department.IT ) { | |
if(employee.year >= 5) { | |
return 0.5 * employee.salary; | |
} | |
return 0; | |
} else { | |
return 1000 + 500 * employee.salary; | |
} | |
} | |
} |
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
public class BonusCalculator { | |
public double getBonus(Employee employee) { | |
switch (employee.department) { | |
case IT: | |
if (employee.year >= 5) { | |
return 0.5 * employee.salary; | |
} | |
return 0; | |
case Sales: | |
return 1000 + 500 * employee.salary; | |
default: | |
return 0; | |
} | |
} | |
} |
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
public class BonusCalculator { | |
public double getBonus(Employee employee) { | |
switch (employee.department) { | |
case IT: | |
if (employee.year >= 5) { | |
return 0.5 * employee.salary; | |
} | |
return 0; | |
case Sales: | |
return 1000 + 500 * employee.salary; | |
case Production: | |
return 0; | |
case Accounting: | |
return 0; | |
case Legal: | |
return 0; | |
case HR: | |
return 0; | |
default: | |
return 0; | |
} | |
} | |
} |
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
interface CalculationStrategy { | |
double calculate(Employee employee); | |
} | |
class ITBonusCalculation implements CalculationStrategy { | |
@Override | |
public double calculate(Employee employee) { | |
return 0; | |
} | |
} | |
class SalesBonusCalculationStrategy implements CalculationStrategy { | |
@Override | |
public double calculate(Employee employee) { | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment