Web Presentation Patters: Page controller and Front controller
Web Presentation Patters: Page controller and Front controller
Jeffrey Han
December 2005
Summary: Details about the prevalent patterns of page controller and front controller. With experiences of three running systems, summarizing some tips about when to and how to use one of them. In addition, the intercepting pattern is introduced as a supplementary.
Contents
Introduction
Page controller
Front controller
Intercepting pattern
Conclusion
Introduction
In the past three applications, the page controller and front controller all have been adapted for the change of details. Utilizing the template pattern, the page controller realizes a stable framework, the future expansion of system can added in the child classes without modifying the integral framework. The page controller can process the complicated business centrally. In asp.net, handler and command are the main parts in this framework. It will bring flexibility to the later maintenance. Certainly, some performance issue will occur. About the intercepting pattern, as I know, the configurable filter chain is my favorite. Each filter node is dependent business logic; you can configure the order or makeup according your requirements.
Page Controller
As started, the application should control the same business in the same place. If you application doesn’t have much more complicated business, you could use it. First the page controller may be thought from the template patter in GOF. As all know, the template pattern defines a framework in his parent class; some concrete realization will be in the respective child class. In asp.net, we make a class named “BasePage” generally, below is the related code:
public class BasePage : Page
{
virtual protected void PageLoadEvent(object sender, System.EventArgs e)
{}
protected void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
PageLoadEvent(sender, e);
}
}
}
A virtual class in the class of
BasePage, the concrete business can be realized in the parent class.
Since the Page controller is a web presentation pattern, we want some
general page tags in the base page. We could use the file of “.inc”;
you can find your web controls here and make them included into the
concrete pages. Hence we have both business logic and web presentation
in our general class (BasePage).
Front controller
In application realization, if a business logic is so complicated that we can consider current pattern. We should know the simple factory well, and pattern of command. There are two parts in this pattern: command and handler.
Originally, we can have an independent command function inheriting from the parent command which has the interface of “Execute”. Utilizing the command factory to produce the related command, the request will be processed by http handler. Actually, we will have a classical framework including the top, left and central parts totally. So we can make some changes about the current pattern. Some ideas are as the following:
1. The actual application should have two types of command, one is for redirecting and another will load the left navigations and top navigations according to the parameters in the xml configuration profile.
2. Another
concern, we should have this functionality: if the left navigation is
activated, there should be no change with the top part in the
framework. Regarding the performance, it will be helpful.
3. Because
of the structure of three parts, so we should have deep understood
about the request. When you send a request in the left or top part of
framework, the entire framework will be posted back.
Intercepting
pattern
About
this topic, I think it adapt to some other business about security and dependent
business objects configured by the xml nodes. In my opinion, this method adapts
to the requirements changed frequently. You can abstract the business to build
some dependent components, and configure your customized business for the
special requirements by different order or different components.
Conclusion
In conclusion, there is no mature architecture of
page layer in asp.net from my opinion. The above patterns can meet most requirements.
If the requirements don’t need complicated logic, you can integrate some common
parts by Page controller pattern. To others you can use the pattern of front
controller. And the intercepting pattern can add the additional flexibility. On
the other hand, the system will have a obscured design, so you should adapt
your design according your concrete requirements. (End)
浙公网安备 33010602011771号