ASP.NET and Design Pattern
Draft-2003-03-26
The readers of this article are middle, senior developers and system architect engineers in ASP.NET.
This article discusses the design mode and software system architecture based on ASP.NET based on ASP.NET.
ASP.NET Introduction ... 1
Perfect Web Tier Application Design Goals ... 2
Solve it ... 3
ASP.NET design mode ... 3
1. Separation of user interface and application logic ... 4
2, provide a central control mechanism ... 4
3. Effective mechanism provided to unit testing and maintenance ... 5
4. Improve the reusability of various components in the system ... 5
5, reduce the time and cost of training ... 5
Web Application Framework. 5
Introduction ... 5
Key technology ... 6
Opinions & feedback ... 7
Software engineers and software vendors based on Microsoft platform have gradually transferred the development platform to .NET, especially in terms of Web programming, ASP.NET has been widely adopted.
The appearance of ASP.NET brings a vacuum zone to its corresponding design pattern. When learning ASP.NET, it is possible to ignore research and learning of its corresponding design patterns. As J2EE is initially used, engineers feel unknown under the new programming model. This paper mainly explores the transition in the design mode of the application of ASP.NET.
Introduction to ASP.NET
Since the purpose of this article is not how church readers use ASP.NET, the following is only introduced only to event-driven programming models in ASP.NET.
The core of ASP.NET uses event-driven programming mode, which will be a fundamental programming change for habits and software engineers who use ASP to write web programs. If you can't change, you will be difficult to master ASP The essence of .NET.
In fact, the WebForm's event drive model is very similar to the message-based programming mode of the Windows window. This also looks out the design intent of the designer of WebForm. The following table compares the events and Dialog events in Page:
Page event
Dialog event
Page_init init_dialog page_load wm_show render wm_paint
At the same time, WebControl in Page is also very similar to the various controls in Dialog. You can set a specific message processing function.
So, if you are designing, write WebForm, you will be more beneficial to imagine WebForm as Dialog.
This can be seen that ASP.NET's event drive model has brought a major change to the design pattern of Web Tier Application, and you cannot design ideas and methods along the ASP.
Perfect Web Tier Application Design Goal
For a long time, the confusion and complex of web tier Application have made people worry, and even make the software masters to write the interest and date of Web Tier Application. Regardless of the technologies you use, JSP, CGI, PHP, HTML, is impossible to make the program structure clear and easy maintenance.
The system architecture of a perfect web tier application should have the following features:
1. The user interface is separated from the application logic, and the role of the developer is effectively separated. The tight coupling of user interface and application logic is the natural defect of web applications, and even use Printf to output the entire page when writing CGI. In order to pursue the perfect usual interface of the web page, the implementation of the application logic is two types of engineers. A good at using Photoshop and Dreamwave graduated from art institutions, one I only know that C and Java tap the keyboard all day, let these two talent mergers are Mission IMPOSSIBLE. In this context, the contradiction between the user interface and the application logic is increasing, and the design pattern that can make the work of these two developers will greatly increase production efficiency. 2, provide a central control mechanism. The web page is interconnected, which provides users with difficulty for maintenance, system logic confusion while providing users. Good design model should provide a central control mechanism, reduce the coupling between the page, and the system is clear.
3. Effective mechanisms provided to unit testing and maintenance.
4. Improve the reuse of various components in the system. Currently, the configuration is usually used to improve the reuse of components, and a standard component can be applied in different systems as long as a simple configuration is simply configured.
5, reduce the time and cost of training.
Solve the way
There are currently two main design patterns for Web Tier Application, which is Microsoft's .NET ASP and Sun's Web Tier Application Framework. Sun's Web Tier Application Framework provides better solutions for JSP and Servelet's Web programming.
For the two modes of mode, non-my ability, nor is it the spirit of discussions in this article. The following will focus on the design pattern of ASP.NET.
ASP.NET design mode
Comparing ASP.NET with traditional Windows applications, it will help build good design ideas, which is the key to the ASP.NET application of design structures. The Windows application is well solved the previously proposed problems, the interface and logic separation, the center control mechanism, which can be effective unit testing; the most important thing is that the Webform is too similar to the Windows application, you are complete Many previous experiences can be applied to WebForm.
The figure below will be more likely to understand the ASP.NET design mode.
This shows:
The Header Bar of Web Page can correspond to the application Menu Bar, they all play a big function point jump. Bottom Bar can be corresponding to STATUS BARs to display some unimportant information such as Copyright et al. The main part of the web page, WebForm in ASP.NET can correspond to Dialog. The WebForm is based on event-driven programming mode and similar to Dialog.
This design pattern uses the Page Template technology, and the specific implementation is shown below:
Since ASP.NET supports custom webControl, you can implement
The following will discuss the ASP.NET solution in detail below as the design objectives proposed in the above:
1. Separation of user interface and application logic
ASP.NET has been well solved this problem, and the interface is saved in the * .aspx file, and the processing code of the event is saved in * .aspx.cs, you can establish a connection with the following code in * .aspx.
<% @ Page language = "c #" codebehind = "WAF_CTRL.ASPX.CS" Inherits = "WAF.WAFCONTROL"%> When designing and implementing WebForm, try to put the code in * .aspx.cs.
2, provide a central control mechanism
ASP.NET does not seem to provide a central control mechanism, which can be seen from the PetStore implemented from Microsoft, and the interconnect relationship between the page is very complicated. As shown in the figure below, the page is a network relationship. This situation will be even worse for large-scale applications. The central control mechanism provided by WAF, the next chapter will focus on.
3. Effective mechanism provided to unit testing and maintenance
The event drive mechanism of WebForm has minimized the coupling of each functional unit. For example, the user's registration interface, information is filled, reviewed, and the saving in the database is completed in a * .aspx, asp.cs, and * .cs, as in the traditional Dialog, this will make the system easier to test.
4. Improve the reusability of various components in the system
ASP.NET provides a good foundation for developing common standard components. More standard components should be designed in system design, and it is more standardized by configuration.
5, reduce the time and cost of training
If you are familiar with the traditional Windows window programming technology, you will find that many experiences can be applied to the ASP.NET.
Web Application Framework
Introduction
Web Application Framework (WAF) is a software architecture based on ASP.NET. It provides a central control mechanism not only makes the system logic clear, and the code is easy to maintain, and it has the following benefits:
1, system function is easy to expand
2, support concentration authentication
3, easy to authorize
4, easy to audit
WAF uses Mediator and Command design patterns to implement a standard configurable control component that allows .NET to work better under the Software system structure of MVC. After using this design mode, the entire web application will appear as follows:
among them
1, WAF_CTRL.ASPX is the only entry point for the entire system
2, WAF_CTRL.ASPX determines the processing requested by the CMD in the request parameter and forwards the request to this page.
3, CMD and execute CMD pages can be done.
Key technology
1, Command
WAF uses Command to achieve central control, avoiding the purpose of interconnection between the page.
For each page, what you need is command, each page can
1. Accept and execute the command.
2, specify the command to process the user request in or
3, send a command directly.
Such as a user login page login.aspx
1. First accept and execute the login command, display the login page, where the Form encodes are as follows