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.
- Previous article:Chen Duxiu's thoughts.
- Next article:How do college students train football?
- Related articles
- The meaning and symbol of pomegranate
- Mulberry silk cotton jacket, cotton cotton jacket, what are the advantages and disadvantages of each?
- Overview of China Game Industry Annual Meeting
- Sage education changes the sense of destiny.
- Indoor games suitable for small class children
- How to keep goldfish in a big fish tank without dying easily?
- The name of a home-cooked restaurant means good. What's the name of a small restaurant?
- How to stand the family photo?
- The rest of my life is here for a big thing - Chairman Xuan Ke of Guizhou Guotan Liquor Industry
- What foundation should be used for a two-story house?