Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of the Concepts of MVC, ORM, CURD and ActiveRecord

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you the concept of MVC, ORM, CURD, ActiveRecord example analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's learn about it!

MVC

MVC is a design pattern that forcibly separates the input, processing, and output of the application. Using MVC applications is divided into three core components: model (M), View (V), and Controller (C), each of which handles its own tasks.

View: a view is the interface that the user sees and interacts with. For old-fashioned Web applications, views are interfaces made up of HTML elements. In modern Web applications, HTML still plays an important role in views, but some new technologies have emerged one after another, including Adobe Flash and markup languages such as XHTML,XML/XSL,WML and Web services. How to deal with the interface of an application is becoming more and more challenging. A big benefit of MVC is that it can handle many different views for your application. No real processing occurs in the view, whether the data is stored online or a list of employees, as a view, it is just a way to output data and allow users to manipulate it.

Model: the model represents 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 such as EJBs and ColdFusion Components to process the database. The data returned by the model is neutral, that is, the model is independent of the data format, so that a model can provide data for multiple views. Because the code applied to the model can be reused by multiple views only once, the repeatability of the code is reduced.

Controller: the controller accepts the user's input and invokes the model and view to complete the user's requirements. So when you click the hyperlink in the Web page and send the HTML form, the controller itself doesn't output anything or do any processing. It simply receives the request and decides which model artifact to invoke to process the request, and then determines which view to use to display the data returned by the model processing.

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

OOP

Object-oriented programming (Object Oriented Programming,OOP) is a kind of computer programming architecture. One of the basic principles of OOP is that a computer program is composed of a single unit or object that can act as a subroutine. OOP achieves three main goals of software engineering: reusability, flexibility and expansibility. In order to realize the overall operation, each object can receive information, process data, and send information to other objects. OOP mainly has the following concepts and components:

Components-Units formed by data and functions in running computer programs. Components are the basis of modules and structures in OOP computer programs.

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

Encapsulation-also known as information encapsulation: ensures that components do not change the internal state of other components in an unpredictable way; their internal state can be accessed only in those components that provide a method to change the internal state. Each type of component provides an interface to contact other components and specifies how other components can be called.

Polymorphism-component references and class sets involve many other different types of components, and the results produced by referenced components depend on the type actually invoked.

Inheritance-allows the creation of subclass components based on existing components, which unifies and enhances polymorphism and encapsulation. Typically, you use classes to group components, and you can define new classes as extensions of existing classes, so that classes can be organized into trees or networks, which reflects the versatility of actions.

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

ORM

Object-relational mapping (Object/Relation Mapping, referred to as ORM) 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 forms of business entity. Business entity is represented as object in memory and relational data in database. There are association and inheritance relationships between objects in memory, but many-to-many associations and inheritance relationships cannot be expressed directly by relational data in the database. Therefore, object-relational mapping (ORM) system generally exists in the form of middleware, which mainly realizes the mapping of program objects to relational database data.

Object-oriented is developed from the basic principles of software engineering (such as coupling, aggregation, encapsulation), while relational database is developed from mathematical theory, there is a significant difference between the two theories. In order to solve this mismatch, object-relational mapping technology arises at the historic moment.

CURD

CURD is an acronym in database technology. The basic function of various parameters developed by a general project is CURD. It represents create (Create), update (Update), read (Read), and delete (Delete) operations. CURD defines basic atomic operations for processing data. The reason why CURD is raised to the height of a technical challenge is that the performance of completing a summary-related activity involving CURD operations in multiple database systems can vary greatly depending on the data relationship.

CURD does not necessarily use the words create, update, read and delete in specific applications, but their functions are consistent. For example, ThinkPHP represents the CURD operation of a 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 are mapped to records, records are mapped to objects, and fields are mapped to object attributes. With the naming and configuration conventions followed, the operation of the model can be realized quickly to a great extent, and it is simple and easy to understand.

The main ideas of ActiveRecord are:

1. Each database table creates a class, and each object instance of the class corresponds to a row record of the table in the database; usually each field of the table has a corresponding Field in the class

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

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

ActiveRecord is more suitable for:

1. Business logic is relatively simple. When your classes basically correspond to the tables in the database one by one, ActiveRecord is very convenient, that is, most of your business logic operates on single tables.

two。 When cross-table operations occur, transaction scripts (Transaction Script) are often used to promote cross-table transactions into transaction scripts.

3. The biggest advantage of ActiveRecord is its simplicity and intuition. A class includes data access and business logic. It is more convenient to use with the code generator.

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

Single entrance

A single entry usually means that a project or application has a unified (but not necessarily unique) entry file, which means that all functional operations of the project are carried out through this entry file. and often the entry file is performed in the first step.

The advantage of a single entry is that the project as a whole is more standardized, because the same entry often has the same rules between different operations. Another aspect is that the advantage of a single entry is that the control is more flexible, because the interception is convenient, such as some permission control, user login judgment and operation can be handled in a unified way.

Or some people will worry that all websites are accessed through an entry file, whether it will cause too much pressure, in fact, this is an unfounded thought.

The above is all the content of the article "sample Analysis of MVC, ORM, CURD, ActiveRecord Concepts". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report