Enterprise Application framework: Decoupling of three-tier architecture

Source: Internet
Author: User
Tags bool

Objective

A while ago a friend took a website to me, let me help add a few small functions, I readily agreed, but when I open the source code, I immediately ran, the entire project even the most basic three-layer framework is not set up, just encapsulates a sqlhelp as a database operation interface, The SQL query statements in the project are everywhere, business logic tightly coupled in the UI logic, see this code, frankly speaking, I do not have any interest, but in favor of human, I bite the bullet, the completion of the basic functions, through this matter, I have a deep thinking of software layering.

Three-tier architecture

When it comes to the three-tier architecture, everyone is familiar with it, and I don't talk much anymore, we build one directly.

The reference relationship of the project is:structwed->bll,model; Bll->dal,model;dal->model. Here's a demo of the program flow, assuming that our database has an order table, our business is for the orders of the list of additions and deletions, then according to the three-tier architecture of the programming model, we need to establish the corresponding model layer entities, data access layer entities and business layer entities, We used ORDERMODEL,ORDERDAL,ORDERBLL to represent the code as follows, because it was just for demonstration, so I didn't provide the corresponding implementation.

Using System;  
Using System.Collections.Generic;  
Using System.Linq;  
Using System.Text;  
      
Namespace Mode  
{public  
    class Ordermodel  
    {public  
        int ID {get; set;}  
      
        public int ProductName {get; set;}  
      
        Public DateTime createtime {get; set;}}}  
Using System;  
Using System.Collections.Generic;  
Using System.Linq;  
Using System.Text;  
      
Using Mode; Namespace DaL {public class Orderdal {///<summary>///inserts data into the order table//  
        /</summary>///<returns> Success: True, failed:false</returns> public bool Insert ()  
        {return true; }///<summary>///Modify Order table data///</summary>///<param name= "mode L "> table Data counterpart entity </param>///<returns> success: True, failed:false</returns> public bool Update (ORD  
        Ermodel model) {return true; ///<summary>///Deletes the record for the specified ID of the order table///</summary>///<param name= ' ID ' > table id</param>///<returns> success: True, failed:false</returns> public bool Delete (int i  
     D) {return true;   }  
    }  
} 
Using System;  
Using System.Collections.Generic;  
Using System.Linq;  
Using System.Text;  
Using DaL;  
      
Using Mode;  
              
        Namespace Bll {public class Orderbll {protected Orderdal orderdal = new Orderdal (); public bool Insert (Ordermodel model) {//Business point 1//Business point 2 ret  
        Urn Orderdal.insert (); ///<summary>///Modify Order table data///</summary>///<param Nam E= "model" > table data corresponding entity </param>///<returns> success: True, failed:false</returns> public bool UPD  
        ATE (Ordermodel model) {//Business point 1//Business point 2 return orderdal.update (model); ///<summary>///Deletes the record for the specified ID of the order table///</summary>///<p  
       Aram name= "id" > table id</param>///<returns> Success: true, Failure:false</returns> public bool Delete (int id) {//Business point 1//Business point 2 return Orderdal.delete (ID)  
        ; }  
    }  
}

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.