Traditional Culture Encyclopedia - Traditional culture - Java expert, help to answer questions about the design mode of DAO factory.

Java expert, help to answer questions about the design mode of DAO factory.

1. what is the purpose of referencing the persondao persondao = newpersondaoimpl () class in the presentation layer?

a: quoting this sentence from personDAO persondao = newpersondaoimpl () shows that the DAO object can be obtained, and it shows that the database person table can be operated through "persondao. method".

2. What does it mean to write another PersonDAOJDBCImpl.java class and change it all to this class at the presentation level?

a: it is clear from the above that the Hibernate implementation of DAO has been completely converted into JDBC implementation. However, the project manager suggested not to destroy the existing Hibernate implementation, but to improve the access efficiency of Hibernate through technical research in the future. Therefore, it is necessary to realize the JDBC implementation of DAO without destroying its Hibernate implementation (PersonDAOImpl.java). Therefore, you can only write a PersonDAOJDBCImpl.java (PersonDAOImpl.java class and PersonDAOJDBCImpl.java class exist at the same time and both realize the PersonDAO interface), which should be implemented by JDBC. The presentation layer will change PersonDao PersonDao = New PersonDaoImpl () to PersonDao PersonDao = New PersonDaoJDBCImpl (), and all the pages used will be changed.

if you use the DAO factory class, you can refer to persondao persondao = daofactory. getpersondaoinstance () in this way;

in case of the above problems, just modify the factory

public class daofactory {

public static persondao getpersondaoinstance ()

{

return new persondaoimpl ();

}

change the above to the following

public class daofactory {

public static persondao getpersondaoinstance ()

{

return new persondaojdbcimpl ();

}

Actually, the consciousness is to use the factory at the beginning, and then it is convenient to modify it.