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

[3464 byte] By [srh99a] at [2007-10-2 2:10:00]
# 1

I would go for the 2nd solution as it is more object oriented and hides the relation of employee to other objects. Think of future releases where employee also have additional references - this would be hidden all in getEmployeeById() and your business classes don't need (necessarily) be changed - only the DAO classes. As an employee always have a location and a department, this should be tight to the employee.

MartinHilperta at 2007-7-15 19:51:15 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

> I would go for the 2nd solution as it is more object

> oriented and hides the relation of employee to other

> objects. Think of future releases where employee also

> have additional references - this would be hidden all

> in getEmployeeById() and your business classes don't

> need (necessarily) be changed - only the DAO classes.

> As an employee always have a location and a

> department, this should be tight to the employee.

I dont have a choice but go with the 1st solution as i have been instructed to do so. Also 1st solution makes more sense to me. If there is any change in Location for example, then i just need to change getLocationById() method to reflect that change. This is a lot cleaner code IMHO.

Anyway the quesiton is how to get another DAO in a sepcific DAO implementation. I am assuming i have to use DAO Factory for that purpose so the question is how to get it.

Thanks

srh99a at 2007-7-15 19:51:15 > top of Java-index,Other Topics,Patterns & OO Design...