Relationship between Dao layer and Business Layer

Source: Internet
Author: User

I have recently worked and found some misunderstandings that I have known. I have been slowly improving my experience at work.

 

As the system grows bigger and bigger, in order to make the system level clear, we are used to hierarchical processing of the system. Currently, it is very popular with three-tier architecture, that is, the common data access layer (DAO ), business and UI ). In the presentation layer, the MVC mode is often used, that is, Model-View-controller. For different hierarchies, many objects are used in mutual access operations, such as DTO (data transfer object), Bo (Business Object), and Po (persistence object.

 

I have been using a three-tier architecture for a long time, but I have never known its true intention (of course, my understanding is also very simple ). In the next semester of my senior year, when I was in the soft power training, when sun xubo told us about the role of the DaO layer, I always thought that Dao was the object of the object relationship task. Of course, what the DaO layer completes is indeed the mutual conversion of object relationship data. However, from the perspective of loose coupling, the information related to the business logic is written to the DaO layer, without the relationship between the underlying architecture and the upper layer, so that the DaO layer and the business layer are tightly pasted. I don't know if you have written this or similar method in the DaO layer, that is, the method used to verify the user identity during logon. In fact, in this method, we have completed a Dao and a business logic. Dao is to get a user in the database based on the user name and password, and the business logic is, check whether this user exists (of course, this business logic is relatively simple ). Because the simple logic makes this design have no major problems, when we need to insert records to the three tables at the same time at a time, we need to use transactions, then I will start and close the transaction at the DaO layer. Let's see if this increases the pressure on the DaO layer.

Such Dao:

1. Obtain a connection

2. Generate a statement

3. Write an SQL statement and put it in statement.

4. Execute statement

5. Disable statement and Connection

6. Return results

 

The Dao layer is like a pipe. It is only responsible for China Unicom. Let's just implement it in the business logic. Therefore, add the transaction to the business logic layer. In this case, we need to modify the above Dao layer object:

Modified Dao:

1. Inject a connection into Dao

2. Production statement

3. Write SQL statements and put them into statement.

4. Execute statement

5. Return results

Put statement and connection close in the business logic layer, so that I can operate multiple Dao while executing an operation, without worrying about enabling or disabling it, access denied.

 

Finally, I would like to briefly introduce that there are a lot of objects in object-oriented programming, which makes it very difficult to remember. If you understand it, it will be easier, because they are all associated with hierarchies.

Po, which maps relationships and objects and is used in Dao layer access

Bo is the object of the business logic, used when processing the business

Dto, in fact, this object is used for data transmission when the server interacts with the client.

 

 

PS: The above is a little bit of personal understanding in learning. It is relatively simple. If there are some mistakes, please give them some advice to help me correct and improve.

Related Article

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.