About Question enthuware.ocpjp.v7.2.1186 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
jagoneye
Posts: 97
Joined: Wed Dec 28, 2016 9:00 am
Contact:

About Question enthuware.ocpjp.v7.2.1186 :

Post 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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1186 :

Post 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.

jagoneye
Posts: 97
Joined: Wed Dec 28, 2016 9:00 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1186 :

Post 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.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 7 guests