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)
; }
}
}