The role of Dao/service/Action hierarchy

Source: Internet
Author: User
The hierarchical structure of software development is very important to the quality of software. For a small project, the service layer may not be very useful, but if a large program is reached, this service layer shows the bid value.
Take a closer look at the two layers of DAO and service. You will find that some classes of datesource databases and the classes in JDBC packages are used in Dao, however, when you call the service in the action, there will be no database-related classes, if you call Dao directly, there will be a large number of database classes in the action. This has some drawbacks to software design layering.
In addition, the DaO layer mainly involves adding, deleting, modifying, and querying databases. In the service layer, the service is more important for processing data logic, for example, to add a record, you must first check whether the record already exists and then check the database. Then, such logic must be completed in the service layer.
Conclusion: The Service is used to make some logical judgment and processing when processing data. The hierarchical software architecture is also improved.
I wonder if my answer is satisfactory to you. Remember to give it a high praise.

Meanings of Dao, service, and action

The main function of an action is to organize the service. For example, if you want to perform permission verification, the request will be obtained by the action. How can you verify it? No matter what the user wants to do with the service. After obtaining the result returned by the Service, determine the Next Hop Based on the result (if the user is verified to exist and the password is correct, go to the logon success page, and vice versa, go back to the logon page)

Now it's the turn of service. Ta manages the business. If the above example is continued, sevice calls Dao to check whether Dao can find the corresponding records when the user asks whether the user is valid or not, when the business receives Dao results, the answer to the action question based on the obtained record is "whether the user is valid or not". Finally, Dao is used as the most "grass-roots" part, what is the relationship between addition, deletion, query, modification, and so on? Dao does not ask, love who is who. Dao is stubborn. Ta only ensures a good relationship with the database. To sum up, action is the scheduling and management redirection of the Management Service (servcie. Service, TA is used to manage specific functions. This is easy to confuse with action. You can understand that action is only responsible for management, while service is responsible for implementation. Dao only completes addition, deletion, query, and modification, of course, you can associate 1-N, N-N, and 1--1, and perform fuzzy, dynamic, and subqueries. However, no matter how complicated Dao is, TA only encapsulates addition, deletion, query, and modification. As for how to implement a function through addition, deletion, query, and modification, TA does not matter.
To sum up the three, we can give an example. actions, such as waiters, what dishes the customer ordered, and the number of tables served on the dishes, are TA's responsibilities. sevice is a cook, the dishes on the menu sent by action are all made by TA; Dao is a kitchen worker, and everything that deals with raw materials is done by TA. Therefore, the work of Dao must meet the requirements of the cook (service), and the cook must meet the requirements of the customers (page users) conveyed by the waiter (action, the waiter naturally serves the customer.
This article is explained to me by Teacher Zhang, Teacher Zhang blog link http://user.qzone.qq.com/953133372

The role of Dao/service/Action hierarchy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.