Deep understanding: single entry MVC ORM CURD ActiveRecord concepts

  • 2020-06-07 04:04:56
  • OfStack

MVC

MVC is a design pattern that coercively separates the input, processing, and output of an application. The MVC application is divided into three core components: the model (M), the view (V), and the controller (C), each of which handles its own tasks.

Views: A view is an interface that the user sees and interacts with. In older Web applications, views are interfaces made up of HTML elements. In newer Web applications, HTML still plays an important role in views, but new technologies are emerging, including Adobe Flash and identity languages like XHTML, XML/XSL, WML and Web services. Dealing with an application's interface is becoming more and more challenging. The big benefit of MVC1 is that it handles many different views for your application. No real processing takes place in the view, whether the data is stored online or a list of employees, but as a view, it simply ACTS as a way to output the data and allow the user to manipulate it.

Models: Models represent enterprise data and business rules. Of the three parts of MVC, the model has the most processing tasks. For example, it might use component objects like EJBs and ColdFusion Components to process the database. The data returned by the model is neutral, meaning that the model is independent of the data format so that one model can provide data for multiple views. Because code applied to the model can be reused by multiple views only once written, code duplication is reduced.

Controller: The controller accepts the user's input and invokes the model and view to fulfill the user's requirements. So when you click the hyperlink in the Web page and send the HTML form, the controller itself does nothing and does nothing. It simply receives the request, decides which model artifact to invoke to process the request, and then determines which view to display the data returned from the model processing.

Now let's summarize the process of MVC. First, the controller receives the user's request and decides which model to call for processing, then the model USES business logic to process the user's request and returns the data, and finally the controller USES the corresponding view to format the data returned by the model and present it to the user through the presentation layer.

OOP

Object-oriented programming (Object Oriented Programming, OOP, object-oriented programming) is a computer programming architecture. One of the basic principles of OOP is that a computer program is composed of a single unit or object that ACTS as a subroutine. OOP achieves the three main goals of software engineering: reusability, flexibility, and extensibility. Each object is able to receive information, process data, and send information to other objects in order to implement the overall operation. OOP has the following concepts and components:

Components - The units of data and function 1 formed in running computer programs. Components are the basis of modules and structure in OOP computer programs.

Abstractness - The ability of a program to ignore certain aspects of the information being processed, that is, to focus on the main aspects of the information.

Encapsulation - also known as information encapsulation: ensuring that components do not change the internal state of other components in unexpected ways; Only components that provide methods for internal state change can access their internal state. Each class of component provides an interface to other components and specifies the methods that the other components call.

Polymorphism - component references and class assemblies involve many other different types of components, and the result of the reference component depends on the type of actual invocation.

Inheritance - allows the creation of subclass components on top of existing components, which unifies 1 and enhances polymorphism and encapsulation. This is typically done by using classes to group components, and it is possible to define new classes as extensions of existing classes so that classes can be organized into trees or networks, demonstrating the versatility of actions.

Component-based programming has become particularly popular in scripting languages because of its abstractness, encapsulation, reusability, and ease of use.

ORM

Object-relational mapping (Object/Relation Mapping, or ORM for short) comes into being with the development of object-oriented software development methods. Object-oriented development method is the mainstream development method in today's enterprise application development environment, and relational database is the mainstream data storage system that permanently stores data in enterprise application environment. Object and relational data are two representations of business entities. Business entities are represented as objects in memory and relational data in database. There are associations and inheritance relationships between objects in memory, while in a database, relational data cannot directly express many-to-many associations and inheritance relationships. Therefore, object-relational mapping (ORM) system 1 generally exists in the form of middleware and mainly realizes the mapping of program objects to relational database data.

Object orientation is based on basic software engineering principles such as coupling, aggregation, and encapsulation, while relational databases are based on mathematical theory. There are significant differences between the two theories. In order to solve this mismatch, object-relational mapping technology came into being.

CURD

CURD is an acronym for database technology, and the basic function of the various parameters developed by a 1-like project is CURD. It represents create (Create), update (Update), read (Read), and delete (Delete) operations. CURD defines the basic atomic operations used to process data. The reason for elevating CURD to the level of a technical challenge is that the performance of an activity that involves summarizing CURD operations across multiple database systems can vary considerably depending on the data relationships.

CURD does not use create, update, read and delete in the specific application, but the function they perform is 1. For example, ThinkPHP is the CURD operation that represents the model using the add, save, select, and delete methods.

ActiveRecord

ActiveRecord also belongs to the ORM layer, which was first proposed by Rails and follows the standard ORM model: tables map to records, records map to objects, and fields map to object attributes. With the following naming and configuration conventions, the operation of the model can be implemented quickly and easily.

The main ideas of ActiveRecord are:

1. Create 1 class for each database table, and each object instance of the class corresponds to 1 row record of the table in the database; Typically each field of a table has a corresponding Field in the class;

2. ActiveRecord is also responsible for persisting itself and encapsulates the access to the database in ActiveRecord, namely CURD; ;

3. ActiveRecord is a domain model (Domain Model), which encapsulates part of the business logic;

ActiveRecord is applicable to:

1. The business logic is relatively simple. When your class basically corresponds to table 11 in the database, ActiveRecord is very convenient.

2. When cross-table operations occur, the transaction script (Transaction Script) is often used to promote cross-table transactions to the transaction script;

3. The biggest advantage of ActiveRecord is its simplicity and intuition. 1 class includes data access and business logic.

These advantages make ActiveRecord particularly suitable for rapid DEVELOPMENT of WEB.

1 single entry

Single entry usually refers to an entry file of a project or application that has a unified (but not necessarily unique) entry file, that is, all functional operations of the project are performed through this entry file, and often the entry file is performed as the first step.

The advantage of a single entry is that the project as a whole is relatively normalized, because the same entry often has the same rules for different operations. Another aspect is that the advantages brought by single 1 entry are more flexible control, because the interception is convenient. For example, some rights control, user login judgment and operation can be handled by one.

Or there are those who worry about the stress of having all the sites accessed through one portal file, but that's probably too much to worry about.


Related articles: