Let's assume I have a User
class and two subclasses Employee
and Customer
. I implemented this hierarchy as a table-per-hierarchy in DB with a column for specifying the type of user. I need to return the right type of object when querying this table.
Do I need separate DAOs for each type of object like CustomerDAO
or EmployeeDAO
, so each return their respective Customer
and Employee
objects. If so how to get them from DAOFactory
without using:
if(type.equlas('customer'))
return customerDao;
else
retrun employeeDao;
Because the types implementing User
could change and I don't want to change conditions every time.
Or is there any other way? Any idea would be appreciated.
Note: I'm not using any ORM framework and not planning to use one.