Talk about the MVC pattern _MVC

Source: Internet
Author: User
Tags generator

1.

How to design a program's structure, this is a specialized knowledge, called "Architecture mode" (architectural pattern), belongs to the methodology of programming.

The MVC pattern is one of the architectural patterns, and it inspires me very much. I think it applies not only to the development of software, but also to other extensive design and organization work.

Here are some of my personal understanding of the MVC pattern, which is not necessarily correct, is mainly used to organize ideas.

2.

MVC is the acronym for three words, which are model, view (view), and controller (control).

This model holds that the program can be divided into three layers, whether simple or complex, from a structural perspective.

1 The top layer is the view that is directly oriented toward the end user. It is provided to the user's operating interface, is the shell of the program.

2 The bottom layer, is the core of the "Data Layer" (Model), that is, the program needs to operate data or information.

3 The middle layer, is the "Control layer" (Controller), it is responsible for the user from the "View layer" input of the instructions, select the "Data layer" of the data, and then the corresponding operation to produce the final results.

These three layers are closely linked, but are independent of each other, and the changes within each layer do not affect the other layers. Each layer provides an external interface (INTERFACE), which is called at the top level. As a result, the software can be modularized, modify the appearance or change the data without modifying other layers, greatly facilitate maintenance and upgrades.

3.

I use the Windows Calculator applet as an example to explain the MVC pattern, although it is not necessarily written using this pattern.

In this calculator program, the outside of those buttons and the top display bar, is the "view layer", those who need to operate the number is "data layer", the implementation of the subtraction of the internal operational steps is "control layer." Each layer performs different functions, and the structure of the entire program is very clear.

If we broaden our imagination, we will find that many programs are essentially this pattern: providing a set of triggers externally (in this case, a button), then performing some internal operations and finally returning the result. Therefore, the application of MVC pattern is very extensive.

4.

In my opinion, not only the programming can be used in MVC mode, household appliances can also be used.

The household microwave oven, for example, can also be understood as a three-layer structure. In the simplest case, the operation of the microwave oven is done with two turntable, one control temperature and another control time. The two dials are the view, and the internal microwave generation device is the "Data Layer" (Model), where the "data" needs to be understood as "core functions." As for the user input information through the turntable, converted to the microwave generator operation, then use the "control layer" to achieve.

If each layer is independent, then the microwave oven to replace a trendy shell, or the internal replacement of more high-power microwave generator, can be achieved without changing the other layers. This is the advantage of the MVC pattern.

5.

Further, if the MVC pattern is interpreted as the three-tier structure of "appearance", "mechanism" and "function/data", then many human organizations can also pass the MVC pattern architecture.

A mall, for example, can be divided into three parts altogether. Part of the warehouse, which is responsible for the provision of goods, this is the "functional layer" (or "Data layer"), and the other part of the retail shop, responsible for the sale of goods, this is its "appearance layer", between the two is "mechanism layer", including the counter and warehouse interaction between the

After this distinction, the structure of the mall becomes very clear, can be optimized for different layers, improve efficiency.

6.

Companies, political parties, governments, hospitals, schools, and so on, these organizations, whether for-profit or non-profit, can be structured from the perspective of the MVC pattern, composed of modules that perform specific functions and can be reused.

I wonder what it would be like if human society were a modular structure.

Finish

From: http://www.ruanyifeng.com/blog/2007/11/mvc.html

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.