Why use Frames

Source: Internet
Author: User

The purpose of using the framework

Programming has a guideline for don ' t Repeat yourself (don't repeat your code). If there is some duplication of code, we should extract the code to encapsulate it as a method. With the accumulation of time a number of methods, we integrate it into the tool class. Tool classes can be integrated into class libraries if they form a scale. A class library is more system-wide. Not only do not re-create the wheel of the project, nor build the wheels that others have made. We just have to use the existing wheels directly.

The framework, too, is created for us to not always write the same code. Framework is created to allow us to focus on the business logic. Framework that extracts the immutable parts of our programming, and lets us focus on the business-related code.

The birth of the MVC framework

It is a sin to write the same code two times, so we need something to liberate us. Soon people developed a set of MVC frameworks.

The idea behind the model-view-Controller architecture pattern is simple: our application must differentiate between the following responsibilities:

The application is divided into three main sections, each of which is responsible for different tasks. Let's take a look at a detailed explanation and an example.

Controller

The controller is in charge of the user's request (the controller receives an HTTP GET or POST request when the user clicks on an element on the graphical user interface (GUI) to perform the operation). Its primary function is to invoke and coordinate the required resources/objects to execute user requests. Typically the controller invokes the appropriate model for the task and selects the appropriate view.

Model

A model is a data rule and data content that is shipped on top of the data, which generally corresponds to the object that the application is managing. In a software system, everything can be abstracted into a data model that can be processed in some way.

What can the MVC framework do for us?

The framework specifies which code the developer writes/does not write, and how to write the code-this is the main problem that the framework solves. The MVC framework implements the MVC pattern. What do you mean? This means that as long as you populate the code according to the requirements of the framework, you can easily implement the MVC pattern.

Who responds to user requests? The framework will tell you
Who is responsible for generating the response interface? The framework will tell you

How do I match URLs? The framework will tell you

How do I accept parameters? The framework will tell you that
How do I interact with a view? The framework will tell you

What are the benefits of MVC?

One of the most obvious benefits of using MVC is that it separates the view presentation from the application logic clearly. Support for different users and different device types has been a common problem for the moment. A request from a desktop computer and a mobile phone should have a different view. The model returns exactly the same data, but the difference is that the controller chooses which view file to use to present the data (we can think of it as a different template). Apart from separating the view from the business logic, the separation of MVC also reduces the difficulty of large-scale application design. The code is also more structured and therefore easier to maintain, test, and reuse. This pattern helps us to clearly differentiate the responsibilities of each part of the program, facilitate program maintenance, code reuse, and testing. The MVC framework provides us with a basic MVC skeleton, as well as many useful features that improve our efficiency and make the development process easier.

Necessity of using the framework

It should be noted that the benefits can only be realized by applying these frameworks to a fairly large-scale program.
If your website, the program is small, then there is no need to overkill.

It is not recommended for beginners to use the framework at the outset, because you do not know what the framework does for you, and this is not conducive to personal growth. In the learning phase, try to do without the framework, and then I will understand the value of the framework.

The difference between a framework and a class library

The main difference between the framework and the class library is the control reversal, the general procedure, and the operation of the program is mastered by the programmer. Program resources initialization, destruction, location lookup, execution logic is we write code implementation. These can be found along the main entrance of the program. But after applying the framework, control has been given to the framework. For example, the controller that has control over the frame is transferred to the framework when the frame parameter is configured.

Second, the framework will tell you what is missing, you just have to write the code, the program can run normally. Class Library Implementation of the code you do not have to write, but the class library does not tell you, programmers need to write what code, the programmer's own psychological number.

The drawbacks of MVC

Because it doesn't have a clear definition, 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, and because the model and view are strictly separated, this also poses some difficulties for debugging the application. Each component needs to be thoroughly tested before it can be used. 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 bring your software to a new level of robustness, code reuse, and architecture.

Why use Frames

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.