Mvc+dao design mode
Blog Category:
- Java
- Java Web Development
Mvc+dao design mode
This digest from: http://www.paper.edu.cn application of Struts framework based on Mvc+dao design pattern Boo Jacin
At the model level, if the data source changes, it inevitably leads to different data access, and JavaBean is inevitably modified to look for new data sources. When the business logic is executed, the implementation of the real theme is not the same, but there must be the same or repeated steps and procedures before and after implementing the real topic, resulting in code duplication. In the servlet, if the real topic implementation class is called directly, it will inevitably bring strong coupling and is not easy to maintain.
In view of the above problems, a DAO pattern (Data Access object) based on the MVC pattern model layer is generated, mainly by the factory class (Factory), the proxy class (proxies), the implementation class (DAOIMPL), the DAO interface, and the Value object Class (VO). and database connection classes.
(1) Factory class: Used to instantiate the object being manipulated.
(2) proxy class: Instead of the real theme implementation class to do all the work, so that the real theme implementation class can concentrate on the real topic, and the preparation and finishing work is done by the proxy class.
(3) Daolmpl class: Complete the business logic processing of the real topic of data access, and get the data information that the end user wants to obtain.
(4) DAO Interface: Defines the specific action method that is required.
(5) Vo class: Encapsulates a database table, 1 VO classes represent a table, and 1 Vo class objects represent 1 records in a table. The properties of the object and corresponding setter methods and getter methods are used to set or get the fields in the database table.
(6) DbConnection class: Dedicated to connect the database, can modify the properties of the class according to different data sources and persistent data storage, reduce the work of the theme implementation class. Mvc+dao mode, further subdivide the business logic processing function, although the amount of early development code has increased, but in the medium and large-sized projects, the advantages are very clear, the business objects and data to achieve a thorough separation, portability and maintainability greatly enhanced, simplifying the business module, improve the overall system readability and development efficiency. Of course, this design pattern still has flaws in the nesting and coupling of DAO objects and SQL statements.