Need advice for the right path
I have 3 classes: Location (refer to Location table), Department (refer to Department table) and Employee (refere to Employee table) with Employee having one way reference to Location and Department.
publicclass Locationimplements java.io.Serializable{
privateint locationId;
private String locationName;
...
}
publicclass Departmentimplements java.io.Serializable{
privateint departmentId;
private String departmentName;
...
}
publicclass Employeeimplements java.io.Serializable{
privateint employeeId;
private String employeeFirstName;
private String employeeLastName;
private Location location;
private Department department;
...
}
I have 3 DAOs : LocationDAO, DepartmentDAO and EmployeeDAO.
publicinterface LocationDAO{
public Location getLocationById (int locationId);
}
publicinterface DepartmentDAO{
public Department getDepartmentById (int departmentId);
}
publicinterface EmployeeDAO{
public Employee getEmployeeById (int employeeId);
}
I have 2 implementations (Microsoft SQL Server and My SQL) of above DAOs.
My question is regarding how to build getEmployeeById() method to get Location and Department object as well. For this purpose I have 2 choices:
1) call getLocationById() and getDepartmentById() methods of the LocationDAO and DepartmentDAO respectively.
2) when retrieving Employee also retrieve data from Location table and Department table; use it to build Location and Department object.
For clarity and easines of code I am going with 1st choice (actually i dont have any choice; the senior wants me to pick 1st choice always and I agree with him). That means I have to instantiate LocationDAO and DepartmentDAO inside getEmployeeById() method. For that I need DAO Factory. But DAO Factory is not available in EmployeeDAO. So I am quite puzzled on how to fix this problem. Please advice.
Thanks

