Ios-mvc detailed

Source: Internet
Author: User
Tags html form ldap

MVC and template concepts for understanding MVC (Model View Controller) models-View-Controllers

MVC originally existed in the Deskt op program, m refers to the data model, v refers to the user interface, C is the controller. The purpose of using MVC is to separate the implementation code for M and v so that the same program can use a different representation. For example, a batch of statistical data can be represented by a histogram, pie chart, respectively. C exists to ensure the synchronization of M and V, and once M is changed, V should be updated synchronously.

Model-View-Controller (MVC) is a software design pattern invented by Xerox PARC in the 80 's for programming language Smalltalk-80, which has been widely used so far. It has been recommended in recent years as a design model for Oracle's Sun Company's Java EE platform and is being welcomed by a growing number of developers using ColdFusion and PHP. Model-View-controller mode is a useful toolbox that has many benefits, but also has some drawbacks.

How MVC works MVC is a design pattern that makes it mandatory to separate the input, processing, and output of an application. Using an MVC application is divided into three core parts: model, view, controller. Each of them handles their own tasks.

View

A view is an interface that the user sees and interacts with. For older Web applications, views are an interface of HTML elements, and in modern Web applications, HTML still plays an important role in the view, but new technologies are emerging, including Macromedia Flash and Image xhtml,xml/xsl , WML, and some other identity languages and Web services.

How to handle an application's interface becomes increasingly challenging. One big benefit of MVC is that it can handle many different views of your application. There is really no real processing happening in the view, whether the data is stored online or an employee list, as a view, it is simply a way to output data and allow the user to manipulate it.

Model

Models represent enterprise data and business rules. Of the three parts of MVC, the model has the most processing tasks. For example, it may use artifact objects such as EJBS and ColdFusion to process the database. The data returned by the model is neutral, meaning that 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, it reduces the repetition of the code.

Controller

The controller accepts the user's input and invokes the model and view to complete the user's needs. So when you click a hyperlink in a Web page and send an HTML form, the controller itself does not output anything and do any processing. It simply receives the request and decides which model component is called to process the request, and then determines which view to use to display the returned data.

Why use MVC

Most Web applications are created using a process like asp,php, or CFML, which has been fully supported by the object-oriented model since the PHP5.0 version. They mix data-tier code like database query statements with presentation layer code such as HTML. The more experienced developers separate the data from the presentation layer, but this is often not easy to do and requires careful planning and ongoing attempts. MVC is fundamentally mandatory to separate them. Although it takes some extra work to construct an MVC application, the benefits it brings to us are beyond doubt.

First, the most important point is that multiple views can share a model, and now more and more ways to access your application. One solution to this is to use MVC, whether your users want a flash interface or a WAP interface, and use a model to handle them. Since you have separated the data and business rules from the presentation layer, you can maximize the reuse of your code.

Since the data returned by the model is not formatted, the same artifacts can be used by different interfaces. For example, many of the data may be represented in HTML, but they may also be represented by Adobe Flash and WAP. The model also has the capability of state management and data persistence processing, for example, session-based shopping carts and e-commerce processes can also be reused by flash sites or wireless networking applications.

Because the model is self-contained and detached from the controller and view, it is easy to change the data layer and business rules of your application. If you want to port your database from MySQL to Oracle, or change your RDBMS-based data source to LDAP, just change your model. Once you've implemented the model correctly, the view will display them correctly, regardless of whether your data comes from a database or an LDAP server. Since the three parts of an application using MVC are independent, changing one does not affect the other two, so you can construct good loosely coupled components based on this design idea.

For me, the controller also provides the benefit of using a controller to join different models and views to complete the user's needs, so that the controller can provide a powerful means of constructing the application. Given some reusable models and views, the controller can select the model to process based on the user's needs, and then select the view to display the processing results to the user.

The advantages of MVCLow Coupling resistance

The view layer is decoupled from the business layer, allowing changes to the view layer code without recompiling the model and controller code, as well as changes in an application's business process or business rules only need to change the MVC model layer. Because the model is decoupled from the controller and view, it is easy to change the data layer and business rules of the application.

highly reusable and adaptable

As technology continues to evolve, more and more ways to access applications are now needed. The MVC pattern allows you to access the same server-side code using a variety of different styles of view. It includes any web (HTTP) browser or wireless browser (WAP), for example, a user can order a product via a computer or via a mobile phone, although the order is different, but the way to order the product is the same. Since the data returned by the model is not formatted, the same artifacts can be used by different interfaces. For example, many of the data may be represented in HTML, but it is also possible to use WAP to represent the commands required to change the implementation of the view layer without any changes to the control layer and the model layer.

lower life-cycle costs

MVC makes it possible to reduce the technical content of developing and maintaining user interfaces.

Rapid Deployment

Using the MVC pattern allows for a considerable reduction in development time, which allows programmers (Java developers) to focus on business logic, and interface programmers (HTML and JSP developers) focus on presentation.

maintainability

Separating the view layer and the business Logic layer also makes Web applications easier to maintain and modify.

facilitates the management of software engineering

Because different layers have their own roles, each layer of different applications has some of the same characteristics, which facilitates engineering and tool-based management of program code.

the drawbacks of MVC

The drawback of MVC is that it doesn't have a clear definition, so it's not easy to fully understand MVC. Using MVC requires careful planning, and because its internal principles are complex, it takes some time to think.

You will have to spend a considerable amount of time thinking about how to apply MVC to your application, as well as the strict separation of the model and view, which also poses some difficulties for debugging the application. Each component needs to be thoroughly tested before it can be used. Once your artifacts have been tested, you can reuse them with no scruples.

Based on the developer's experience, because developers divide an application into three parts, using MVC also means that you are going to manage more files than ever before, which is obvious. It seems like our workload has increased, but remember that this is nothing compared to the benefits it can bring us.

MVC is not a good fit for small or medium-sized applications, and spending a lot of time applying MVC to applications that are not large in size will often outweigh the costs.

The MVC design pattern is a good way to create software, and some of the principles it advocates, such as content and display, may be better understood. But if you want to isolate the artifacts of models, views, and controllers, you may need to rethink your application, especially the architectural aspects of your application. If you accept MVC and have the ability to cope with the extra work and complexity it brings, MVC will give your software a new level of robustness, code reuse, and structure.

Ios-mvc detailed

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.