Talk about the MVC pattern--a blog that goes from Nanyi

Source: Internet
Author: User
Tags generator


1.

How to design a program structure, this is a specialized knowledge, called "Architecture pattern" (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 is not only suitable for developing software, but also for other extensive design and organization work.

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

2.

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

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

1) The topmost layer is the "view layer" that is directed towards 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 "data layer" (Model), which is the data or information that the program needs to manipulate.

3) The middle layer, is the "Control Layer" (Controller), which is responsible for the user from the "view layer" input instructions, select the "Data layer" in the data, and then the corresponding operation, resulting in the final result.

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 is externally provided with an interface (Interface) for invocation on the above layer. In this way, the software can be modular, modify the appearance or change the data without modifying the other layers, greatly facilitate maintenance and upgrade.

3.

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

In this calculator program, the external buttons and the topmost display bar, is the "view layer", those who need to operate the number is the "Data layer", the implementation of those internal operations subtraction is "control layer." Each layer performs different functions, and the structure of the whole program is very clear.

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

4.

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

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

If each layer is independent, replace the microwave oven with a trendy outer shell, or internally replace the more powerful 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 a three-tier structure of "appearance", "mechanism", and "function/data", many human organizations can also pass the MVC schema.

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

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

6.

companies, political parties, governments, hospitals, schools, and so on, these organizations, whether profitable or non-profit, can be structured from the perspective of the MVC pattern, consisting of modules that perform specific functions and are reusable.

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

Finish


Original link: 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.