Reusable webapp的思考(2): Web Presentation Patterns


Reusable webapp的思考(2): Web Presentation Patterns

Published on Fri 03 Apr 2009 12:04 ( 11 months, 2 weeks ago)
学习 Web

今天从Microsoft Patterns & Practices里阅读了一些web presentation patterns.

image

http://msdn.microsoft.com/en-us/library/ms998516.aspx

image

MVC

MVC是最基本的web presentation pattern, Django并不是典型的MVC, 而是所谓MTV, 但其实是一样的东西,我的理解Django的V相当于C, T相当于V.

我个人以为RoR方式的MVC设计更为优雅一些,最近发布并且开源的ASP.NET MVC非常接近RoR的设计。RoR和ASP.NET MVC中每一个controller class 以及对应的model, view接近于django中的一个web app.  RoR的我好久不碰不清楚了,ASP.NET中可以把一组对应的controller, model打包放进一个assembly, 因此应该也可以达到类似django水平的重用方式。

image

我觉得MVC对处理非常简单而清晰的业务是非常合适而且清晰的,这个从各个基于MVC的框架已经可以看到这点。然而几乎所有的MVC框架给出的例子也都是“简单”而清晰的例子,实际的站点往往是要更复杂。

注:不过从microsoft的Implementing Model-View-Controller in ASP.NET文章看来,至少这篇文章所理解的MVC和我理解的略有些区别。

Page Controller

Page Controller, which is a refinement of Model-View-Controller and is appropriate for the next level of complexity. This pattern uses a controller at the page scope, accepts input from the page request, invokes the requested actions on the model, and then determines the correct view to use for the resulting page. Duplicate logic, such as validation, is moved into a base controller class.

光看说明觉得和MVC差不多,但这是ASP.NET的web form实现方式,JSF(Java Server Face)是类似的。

我认为page controller模式对部件可重用的意义较大,看看asp.net有多少现成而易用的组件就知道了。 这种方式从某种程度上也更接近传统的桌面软件开发模式 --可以把一个页面理解成为一个窗口,叶面上的部件理解成为窗口上的控件,控件自己负责自己的view, 能自己实现部分control, 但更多能给父窗口发送通知,在窗口层次上统一协调窗口内的部件。

可以把website理解成为一个SDI(Single Document Interface)的应用,每个URL对应一个不同的SDI文档, 页面内的组件是SDI文档窗口上的部件 --当然这些部件会被广泛地重用。

image

Front Controller

Front Controller, the next pattern in this catalog, is also a refinement of Model-View-Controller. In a front controller, all of the requests are channeled through a single, usually, two-part controller. The first part of the controller is the handler, and the second part is a hierarchy of Commands [Gamma95]. The commands themselves are part of the controller and represent specific actions that the controller triggers. After the action has executed, the command chooses which view to use to render the page. Usually, this controller framework is built to use a configuration file that maps requests to actions, and is therefore easy to change after it is built. The tradeoff, of course, is in the level of complexity inherent in this design.

image

其实这个front controller模式不就是现在主流的MVC框架本身实现方式吗? ASP.NET MVC框架的文章明确说了ASP.NET MVC就是Front Controller模式:

It uses a Front Controller pattern that processes Web application requests through a single controller. This enables you to design an application that supports a rich routing infrastructure. For more information, see Front Controller on the MSDN Web site.

这个pattern我看是框架实现的pattern, 和上面两个并列有些不合适。 这个pattern显然对应用/部件如何重用没有什么帮助。:(

--

这套文章Microsoft色彩比较严重,读下来反而觉得有些糊涂了,不知道是因为我自己糊涂了,还是这些文章作者自己把类似的概念搞在一起给弄得糊涂了。


Related posts:


Search related in web:

Custom Search

RSS Feed

One click subscribe this blog in your google reader!

Be social!


Want to say something here? please sign in



Blog posts link to this page
What are friends tweeting?
Tags cloud
Monthly Archives