Page Controller页面控制器实现

A Page Controller is one object or file declaration designed to handle the request for one logical web page or action.

With a simple mapping between a page request (URL) and files, this is the default pattern for scripting solutions (PHPASP, JSP). A single file handles the request for a specific page. This simple mechanism mirrors how static web pages are handled.

Scripting solutions provide a poor separation between the view and the controller when implementing a Model View Controller architecture. This can make testing and reuse difficult. Also See Template View for separating the View from other application logic.

The primary responsibility of the page controller as part of Model View Controller is to process input and coordinate the model and the view. The page controller extracts information from the web server request and invoke an action on the model or calls a view based on that information. Page controller is distinguished from a Front Controller in that the page controller operates on only a single logical page, where aFront Controller performs this functions for a set of logical pages.

页面控制器紧紧操作一个逻辑页面,而前端控制器则操作一系列页面。

Page Controllers are useful on web sites with static navigation structures.

Base Controller

When multiple page controllers share duplicate logic, a common practice is to move that logic to a base page controller which each page controller can inherit from. This is one way of implementingCentralized Request Logic.

ASP.NET provides a special mechanism for implementing base controllers in scripts, called Code Behind.

When the base controller class begins to have special case logic in it for types of requests, it might be a good idea to consider a Front Controller instead.

当多个页面控制器拥有共同的逻辑时,一个常见的经验就是把共同逻辑移到base page controller,页面控制器继承基类。这是实现集中请求逻辑的方式。

当base controller开始对不同的请求有不同的处理逻辑时,这是考虑前段控制器是一个好主意,

上面转自:http://www.phpwact.org/pattern/page_controller

martin fowler解释:

page controller: An object that handles a request for a specific page or action on a Web site.

Most people's basic Web experience is with static HTML pages. When you request static HTML you pass to the Web server the name and path for a HTML document stored on it. The key notion is that each page on the Web site is a separate document on the server. With dynamic pages things can get much more interesting since there's a much more complex relationship between path names and the file that responds. However, the approach of one path leading to one file that handles the request is a simple model to understand.

As a result, Page Controller has one input controller for each logical page of the Web site. That controller may be the page itself, as it often is in server page environments, or it may be a separate object that corresponds to that page.

参考:http://www.martinfowler.com/eaaCatalog/pageController.html

更多:http://www.onlamp.com/pub/a/php/2004/10/14/page_controller.html

http://www.uml.org.cn/sjms/200812302.asp

原文地址:https://www.cnblogs.com/youxin/p/3534412.html