About Question enthuware.ocpjp.v7.2.1107 :
Moderator: admin
About Question enthuware.ocpjp.v7.2.1107 :
I couldn't figure out why only option first is correct ? i believe second option is more correct.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1107 :
Not entirely true. The main purpose of DAO is to remove database logic from business logic.
You could use the program to an interview principal while implementing DAO as well but that is not fundamental to the DAO as such. In other words, you can choose not to have a DAO interface and still use the DAO class directly.
HTH,
Paul.
You could use the program to an interview principal while implementing DAO as well but that is not fundamental to the DAO as such. In other words, you can choose not to have a DAO interface and still use the DAO class directly.
HTH,
Paul.
-
- Posts: 77
- Joined: Sun Jun 30, 2013 10:04 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1107 :
"To reduce code complexity in business objects" is a bit ambiguous.
I believe a better answer for option A) would be
"To reduce code complexity in business objects and hide the data access implementation from its client."
If you say
"To reduce code complexity in business objects"
by itself, the person who reads it thinks
"This could be stand alone JavaBeans on a desktop."
If no reference is made to database access, then why would one select the DAO pattern?
I selected option B) because when you use the DAO pattern,
your class implements an interface DAO.
My basic understanding of the DAO pattern is to place the business logic in a tier,
that makes it independent of the RDBMS.
So if you switch from Oracle 11G to DB2 10.1,
only a small amount of Java code will have to be changed.
Please confirm.
I believe a better answer for option A) would be
"To reduce code complexity in business objects and hide the data access implementation from its client."
If you say
"To reduce code complexity in business objects"
by itself, the person who reads it thinks
"This could be stand alone JavaBeans on a desktop."
If no reference is made to database access, then why would one select the DAO pattern?
I selected option B) because when you use the DAO pattern,
your class implements an interface DAO.
Code: Select all
public class User {
private int userId;
private String name;
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public interface UserDAO {
public void insert(User user);
public void update(User user);
}
public class UserDAOImpl implements UserDAO {
public void insert(User user) {
// insert user into user table
}
public void update(User user) {
// update user information in user table
}
}
that makes it independent of the RDBMS.
So if you switch from Oracle 11G to DB2 10.1,
only a small amount of Java code will have to be changed.
Please confirm.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1107 :
Yes, it is true that it is a bit ambiguous. But it is there because you can expect similar statements in the exam.
Your understanding about DAO is correct but it is not just the change in database. It protects upper layer code even from a change in persistence mechanism i.e. it allows you to change from say Hibernate to iBatis.
HTH,
Paul.
Your understanding about DAO is correct but it is not just the change in database. It protects upper layer code even from a change in persistence mechanism i.e. it allows you to change from say Hibernate to iBatis.
HTH,
Paul.
-
- Posts: 97
- Joined: Wed Dec 28, 2016 9:00 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1107 :
Suppose the first option was not there. Then the option
"Program to an interface and not to an implementation" principle.
would be correct or not?
"Program to an interface and not to an implementation" principle.
would be correct or not?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1107 :
No, you can have a DAO without using any interface. See this:
http://www.oracle.com/technetwork/java/ ... 38824.html
In the above link it uses:
DAOFactory cloudscapeFactory =
DAOFactory.getDAOFactory(DAOFactory.DAOCLOUDSCAPE);
the call returns an object of class CloudscapeCustomerDAO that implements CustomerDAO.
But you could have a CustomerDAO abstract class as well or even a concrete one if you don't want multiple kinds of CustomerDAOs.
Of course, it may not be as flexible but it would still be a valid DAO.
http://www.oracle.com/technetwork/java/ ... 38824.html
In the above link it uses:
DAOFactory cloudscapeFactory =
DAOFactory.getDAOFactory(DAOFactory.DAOCLOUDSCAPE);
the call returns an object of class CloudscapeCustomerDAO that implements CustomerDAO.
But you could have a CustomerDAO abstract class as well or even a concrete one if you don't want multiple kinds of CustomerDAOs.
Of course, it may not be as flexible but it would still be a valid DAO.
Who is online
Users browsing this forum: No registered users and 3 guests