I am not too familiar with enum classes in java. And was wondering if this is an appropriate way to do the following.. (or if there is a better way of doing this)
Essentially what I am trying to do is I have a list of Employees and I'd like to associate with it specific subclasses of parent classes.
public enum Employees {
BOB (new Level2Salary(salaryPlan), new SystemsDept())
MARY (new Level3Salary(salaryPlan), new SoftwareDept()),
SUSAN (new Level2Salary(salaryPlan), new SystemsDept()),
PETER (new BaseSalary(salaryPlan), new TestDept());
private Salary salary;
private Dept dept;
Employees(Salary salary, Dept dept){
this.salary = salary;
this.dept = dept;
}
public Salary getSalary() {
return salary;
}
public Salary getDept() {
return dept;
}
}
public class Level2Salary extends Salary {
private SalaryPlan salaryPlan;
public Level2Salary(SalaryPlan salaryPlan) {
this.salaryPLan = salaryPlan;
}
}
public class SystemsDept extends Dept {
public SystemsDept(){}
}
}
I want to be able to do this so when I call Employees.BOB.getSalary() it will return the appropriate instantiated subclass that is associated with this enum value. (i.e. Level2Salary subclass)
If anyone has better suggestions of this besides using enums, feel free to suggest. Thanks
List<Employee>where Employee is class with members SalaryPlan and Dept. If you'd like I'll write a more detailed answer when i get time