Got this interview question which i'm wondering about:
A software company designed an app that manages employees and, among other functions, calculates Salary.
The current structure which fits the customer's requirements is:
abstract Class Employee;
Class Manager extends Employee;
Class Engineer extends Employee;
The customer would now like to add the ability to support different types of salary calculations for employees who work on an hourly wage, monthly salary. Both Engineer and Manager can be either.
The customer also notified the software company that they will add a number of other types of salaries in the future.
The Question - How would you design this? Does if fall in any design pattern solution?
Thanks!
Apply the strategy pattern:
http://en.wikipedia.org/wiki/Strategy_pattern
Make "Salary_Calculation" a strategy associated to Employee. "Salary_Calculation" should be an interface or an abstract base class, and each salary calculation model is a subclass of that.
Add a SalaryCalculator interface and instantiate a SalaryCalculator object during the Employee object's construction using the salary type. The SalaryCalculaotr object will take care of salary calculations for each salary type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With