After using MVC for team development, I realized the convenience of object-oriented software development. When using MVC, the low coupling between layers makes the relationship between them very much, which reduces the degree of dependency between modules.
First, we will introduce the significance of MVC and the usage and functions between different layers.
1) entity layer. It is mainly used to declare the carrier for transferring data between the view layer and the business logic layer. It usually represents a meaningful record composed of one or more tables in the source and project database.
2) business logic layer. Provides data to the view layer according to the business logic. The class in this project has the right to decide whether to call the database access layer method based on the business logic.
3) database access layer. The business logic layer provides methods to access data.
4) view layer. This article mainly uses website development as an example. Displays, adds, edits, and deletes data.
The structure of the project I created in:
NetMVC is the so-called view layer. Entity is an Entity layer used to declare all variables to be used during development. DAL is the database access layer, mainly used to access the database through all operations. BLL is the business logic layer. It processes the business logic sent from the view layer and then passes it to the database access layer for processing.
This example mainly demonstrates the implementation of the login page. The Entity Layer Code is as follows:
Using System; using System. collections. generic; using System. text; namespace Entity {public class UserInfo {private int UserId; /// <summary> /// user ID // </summary> public int UserId1 {get {return UserId;} set {UserId = value ;}} private string username; // <summary> // Logon account name // </summary> public string Username {get {return username ;} set {username = value ;}} private string password; // <summary> // logon Password /// </summary> public string password {get {return password ;} set {password = value ;}} private int loginCount; // <summary> // Number of logins /// </summary> public int LoginCount {get {return loginCount ;} set {loginCount = value ;}} private DateTime regDate; // <summary> // registration time /// </summary> public DateTime RegDate {get {return regDate ;} set {regDate = value ;}} private DateTime lastLoginDate; /// <summary> /// last logon time /// </summary> public DateTime LastLoginDate {get {return lastLoginDate;} set {lastLoginDate = value ;}} private bool isForbidden; private string passwordQuestion; // <summary> // a password retrieval error is prompted. /// </summary> public string PasswordQuestion {get {return passwordQuestion ;} set {passwordQuestion = value ;}} private string passwordAnswer; /// <summary >/// retrieve the password /// </summary> public string PasswordAnswer {get {return passwordAnswer ;}set {passwordAnswer = value ;}}}}