What I need to make in Dao Factory is something like this
I have DaoFactory class, BaseDao (Parent Dao), and then where UserDao, ProductDao will extends BaseDao
In my use case, I would like to
DaoFactory.getDao("user").insert();
DaoFactory.getDao("product").update();
where
DaoFactory.getDao("user") will implicitly return UserDao instance.
But inside this getDao implementation, it is not hardcoding the UserDao and ProductDao instance inside.
Means, when the developer add new Dao class such as MemberDao,
then he needs not to change DaoFactory class but just using DaoFactory.getDao("member") to return his MemberDao
I am guessing using this type of method:
However, what the result I had got is:
when I DaoFactory.getDao("product")
the implementation found is ProductDao, and it is true; BUT, the type remains BaseDao
Means something like this BaseDao dao_i = new ProductDao();
and means whatever attributes defined inside ProductDao can not be called from dao_i, because BaseDao type higher than ProductDao.
what I really need is that ProductDao dao_i = new ProductDao();
So the importance of this question is how to return the dynamic type reference?
public <T> T getDao(String name)
Help me brainstorming, thanks.
I have DaoFactory class, BaseDao (Parent Dao), and then where UserDao, ProductDao will extends BaseDao
In my use case, I would like to
DaoFactory.getDao("user").insert();
DaoFactory.getDao("product").update();
where
DaoFactory.getDao("user") will implicitly return UserDao instance.
But inside this getDao implementation, it is not hardcoding the UserDao and ProductDao instance inside.
Means, when the developer add new Dao class such as MemberDao,
then he needs not to change DaoFactory class but just using DaoFactory.getDao("member") to return his MemberDao
I am guessing using this type of method:
However, what the result I had got is:
when I DaoFactory.getDao("product")
the implementation found is ProductDao, and it is true; BUT, the type remains BaseDao
Means something like this BaseDao dao_i = new ProductDao();
and means whatever attributes defined inside ProductDao can not be called from dao_i, because BaseDao type higher than ProductDao.
what I really need is that ProductDao dao_i = new ProductDao();
So the importance of this question is how to return the dynamic type reference?
public <T> T getDao(String name)
Help me brainstorming, thanks.