27. An approach to MVC model in the development of EFW Framework BS System

Source: Internet
Author: User
Tags ldap sin

back to the "open source" EFW Framework Series article index

EFW Framework Source code download V1.3:http://pan.baidu.com/s/1c0dado0

EFW Framework Instance source code download: Http://pan.baidu.com/s/1eQCc69G

The previous chapter "EFW frame broken cocoon into a butterfly" through the apple told own some programming experience, has the understanding to the system architecture, also has the EFW framework the MVC pattern origin. The whole process is divided into five stages:

ASP website : Do ASP site when there is no system concept, is a few pieces of code copy and paste into a different appearance, the function is so several enterprise website, which will think of code reuse, maintenance and expansion;

Desktop system : Changed the company began to contact the CS structure of the system, know the importance of business requirements, often a function with the changes in the business often repeated changes, this time began to have a thinking of the code;

three-layer architecture : With the understanding of the original code, began to break the original model, the understanding of the system architecture of a qualitative breakthrough in the project to fully practice the layered model;

Web System (extjs+aspx): With the development of technology began to turn to the web system, which is a transition to the understanding of the web system;

EFW Framework (jqueryeasyui+httphandler+controller+objectmodel+dao+entity): Only experienced some lessons, and in the process of growing up thinking, summary, To achieve a practical and convenient framework;

This article highlights:

1.MVC Introduction

2. Compare the pros and cons of EFW MVC with ASP.

3. Why to use MVC

Seven Sins of 4.AJAX

1.MVC Introduction

MVC is a pattern of creating WEB applications using MVC (Model View Controller-View-controller) Design:

  Model is the part of your application that handles application data logic. Typically, model objects are responsible for accessing data in the database.

View is the part of the application that handles the display of data. Typically views are created from model data.

A controller is a part of an application that handles user interaction. Usually the controller is responsible for reading data from the view, controlling user input, and sending data to the model .

  MVC layering helps you manage complex applications because you can focus on one aspect at a time. For example, you can focus on view design without relying on business logic. It also makes testing of applications easier.

The MVC hierarchy also simplifies group development. Different developers can develop views, controller logic, and business logic at the same time.

In the EFW framework:

Model: The ObjectModel, DAO, and entity are represented

View: The representative is Jqueryeasyui

Controller: The representative is Webcontroller

Many programmers often confuse frame patterns with design patterns, thinking that MVC is a design pattern. In fact, they are completely different concepts. The two concepts of frame and design pattern are always easy to be confused, but there are still differences between them. Frameworks are often code reuse, while design patterns are reuse, schemas are in between, part of code reuse, partial design reuse, and sometimes analysis can be reused.

2. Compare the pros and cons of EFW MVC with ASP .

Advantages of EFW MVC:

1. The interface code can not be too flexible, the ASPX interface can not take <%%> directly from the background to get the data, aspx file only HTML tags, data requests are placed in the JS file, to complete the code separation

2. The development system must select a major interface framework, such as Jqueryeasyui, so that the interface code corresponds to the controller, directly interacting based on JSON data, and is a Jqueryeasyui-based data structure of the JSON data , which can simplify the workload of our data structure transformation;

3. Be sure to use Ajax in jquery to request data from the controller, do not use other messy ways;

4.AspNetMVC has a complex routing mapping system, can be very flexible custom configuration, and EfW in the MVC is not so complex, very simple just specify the controller and method in the URL parameter, will call the HTTP request method in the specified controller;

Disadvantages of EFW MVC:

1. Interface layer Data conversion can only be handled using JavaScript scripts, not the use of dynamic scripting language, which increases the workload of JavaScript script, for future maintenance or there are some challenges.

2. Use AJAX for data interaction, not be recognized by search engines, and Ajax has some drawbacks, see the following "Seven Sins of Ajax"

Benefits of ASP:

1.aspx code can write dynamic scripting language, a bit back to the ASP that encoding way

2. The application uses a controller to control the request and provides native urlrouting functionality to rewrite the URL.

Disadvantages of asp:

1. Awkward view: Can not let me take the logic

I personally think that the first ASP.NETMVC is the implementation of the view. In this framework, views are implemented using ASPX files. In terms of the need to present the data, the ASP.NETMVC general approach is that the controller is responsible for invoking the model to complete the reading of the data and passing the data that needs to be rendered through viewdata to the view and selecting a view rendering. The selected view is responsible for reading, decomposing, and then using a certain logical statement to render the corresponding data in the ViewData.

In this way, a certain logical statement is required in the view, such as converting the data in ViewData into a type conversion statement of the corresponding type, and if a different content needs to be rendered according to a condition, the branch statement is required, while the usual tabular data rendering requires a looping statement. As a result, we can see that the view is filled with <%%>, if, foreach and so on.

2. Support for Ajax: still very inconvenient

We know that it is commonplace to add AJAX elements to a Web application, and Microsoft certainly knows that, so in ASP. ASP. NET AJAX and jquery are naturally supported, and a ajaxhelper is provided to complete some ancillary operations. However, this ajaxhelper function is far from enough.

Because of the nature of the ASP.NETMVC, the URL of an action is not fixed. Therefore, when the action is requested, the URL is not hardcoded in the page, but is generated dynamically by Html.ActionLink. There is a problem, what about AJAX requests? Of course, there is a special helper method for clicking on a link or submitting a form-triggered action,ajaxhelper, but it can be problematic if an AJAX request is not triggered by a link or form. After all, you can't hard code the URL in JS.

in short, the AspNet MVC comparison EFW MVC should be more flexible and suitable for more scenarios, while the EFW framework restricts some functionality, but gives us less opportunity to learn and make mistakes, so that EFW MVC is better suited to the development of industry software, Not very suitable for the development of Internet sites;

3. Why to use MVC

Most Web applications are created in a procedural language like asp,php, or CFML. 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 no doubt.

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 antagonistic, changing one does not affect the other two, so you can construct good loosely coupled components based on this design idea.

Seven Sins of 4.AJAX

The seven Sins of Ajax http://tech.163.com/05/1009/18/1VL1PAP300091589.html

One of the sins: poor support for search engines

Crime II: Writing complex, error-prone

The third of sin: redundant code more

Sin Four: Destroying the original standards of the Web

Sin V: lack of a browser without a standard dispute, without back and history

Sin VI: XML is only used for the pretence

Sin Seven: The world is so big but can't find its own home

Also: So much so that we use MVC to fundamentally separate the interface from the logic, but let's not over-peel all the associations, because the stripping is bound to complicate your code, so there is a proper balance, which depends on the complexity of the business function. The MVC in the EFW framework has been honed in such a way that complex business functions are completely separated, and simple business functions are partially separated.

27. An approach to MVC model in the development of EFW Framework BS System

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.