Page 1 of 1
About Question enthuware.ocpjp.v7.2.1186 :
Posted: Fri Jan 06, 2017 12:50 pm
by jagoneye
Code: Select all
StudentDAO studentDao = StudentDAO.getImpl("StudentDAOJDBCImpl");
This option can also be correct? If not then why?
Here you can pass different implementation names which will also act like a
Factory method.
Re: About Question enthuware.ocpjp.v7.2.1186 :
Posted: Fri Jan 06, 2017 11:09 pm
by admin
It is not correct because the name StudentDAOJDBCImpl is hardcoded. You will require a code change in this class to use a different impl.
Re: About Question enthuware.ocpjp.v7.2.1186 :
Posted: Sat Jan 07, 2017 6:55 am
by jagoneye
Okay got it. I was thinking one level above maybe. Like if this code was using say jdbc type 3 driver to connect to multiple database types so in that case you need to pass the database name in the constructor and it will get you the required connection hence I thought of the first option. But I guess I was overthinking it because this question can be assumed to be using say jdbc type 4 driver and you are connected to one database maybe later you want to migrate to other database say from mysql to ms sql server then the correct answer is as given in this question.