论坛首页 Java企业应用论坛

Rod Johnson(Spring框架的作者)对Struts的评价

浏览 8339 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2004-08-21  
在《Expert One-on-One J2EE Development without EJB》一书中,Rod Johnson(Spring框架的作者)对Struts的评价:

    Struts1.1是目前公认标准的基于MVC模式Web框架,但是离的完善却相距甚远。它的使用必须完全依赖于具体的框架类,比如它必须对Action、ActionForm的继承实现和Web层的Servlet对象以及Struts本身的API紧紧耦合等。事实上,Struts不能将领域对象作为FormBean使用,带来了很多额外的FormBean,导致了不必要的复杂。它的视图部分也只支持Jsp,不能很好的支持其它视图技术。

    Struts的优势并不是它本身的设计,而是拥有广泛的使用群体,丰富的文档以及很好的工具支持。无论如何,随着其它Web框架快速的成长和普及,有WebWork2、Spring Web MVC和Tapestry,我认为Struts的这些优势都会逐渐消失。

英文原文:

引用

Struts 1.1 is the current de-facto standard for web MVC, but it is far from perfect. Its reliance on deriving from concrete framework classes like Action and ActionForm restricts implementation choices and ties web tier objects to the Servlet and Struts APIs. The fact that Struts cannot handle domain objects for forms leads to an unnecessary proliferation of form holder classes. Its view handling is JSP-centric and not
well suited for other view technologies.

The advantages of Struts are not in its design but in its broad acceptance, abundant documentation, and good tool support. However, we expect that these advantages will be eroded as other web frameworks grow in popularity: notably, WebWork2, Spring web MVC, and Tapestry.

   发表时间:2004-08-21  
moxie 写道
事实上,Struts不能将领域对象作为FormBean使用,带来了很多额外的FormBean


这不是事实。实际上,如果FormBean同时实现领域对象(准确说是DTO)的接口,那么尽管不能将领域对象作为FormBean使用,却可以将FormBean作为领域对象使用,所以也不算“额外的FormBean”。譬如说:

        // in a struts action ...
	public ActionForward execute(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response);
		throws Exception 
	{
                /*
                   form's actual type is MyForm
                   MyForm extends ActionForm implements MyDomain
                */
                MyDomain domain = (MyDomain); form;
                MyService service;
                service.useDomainObject(domain);;
0 请登录后投票
   发表时间:2004-08-21  
ActionFormBean做VO有一点点不好的地方是VO依赖于struts,最后变成使用VO的Model部分也多多少少与struts有关了
0 请登录后投票
   发表时间:2004-08-21  
gigix 写道:
引用

将FormBean作为领域对象使用

我不同意这种做法,我的领域对象要完全依赖于Struts的FormBean,坚决反对。
0 请登录后投票
   发表时间:2004-08-21  
moxie 写道
gigix 写道:
引用

将FormBean作为领域对象使用

我不同意这种做法,我的领域对象要完全依赖于Struts的FormBean,坚决反对。


你还没想清楚呢。领域对象怎么会依赖Struts呢?只不过是FormBean实现了你的领域对象的接口,可以把界面上的数据传给你的service去使用,仅此而已。这里的关键是:领域对象也是一个接口,你自己在下面有一个基于POJO的实现,在web层上也可以有一个基于FormBean的实现。这有什么问题吗?

public interface MyDomain {
public class MyDomainImpl implements MyDomain {
public class MyFormBean extends FormBean implements MyDomain {
public interface MyBusinessService {
    public void useDomainObject(MyDomain domain);;


明白了吧?
0 请登录后投票
   发表时间:2004-08-21  
引用

你还没想清楚呢。领域对象怎么会依赖Struts呢?只不过是FormBean实现了你的领域对象的接口,可以把界面上的数据传给你的service去使用,仅此而已。这里的关键是:领域对象也是一个接口,你自己在下面有一个基于POJO的实现,在web层上也可以有一个基于FormBean的实现。这有什么问题吗?

确实可以,不过有点牵强,实际应用中未必可取。不如直接用一个转换层将form转换成DTO,各层的概念清晰一些。
0 请登录后投票
   发表时间:2004-08-21  
gigix 写道

你还没想清楚呢。领域对象怎么会依赖Struts呢?只不过是FormBean实现了你的领域对象的接口,可以把界面上的数据传给你的service去使用,仅此而已。这里的关键是:领域对象也是一个接口,你自己在下面有一个基于POJO的实现,在web层上也可以有一个基于FormBean的实现。这有什么问题吗?

public interface MyDomain {
public class MyDomainImpl implements MyDomain {
public class MyFormBean extends FormBean implements MyDomain {
public interface MyBusinessService {
    public void useDomainObject(MyDomain domain);;


明白了吧?


hehe,这个做法很有意思。下回我把这种思路用到别的地方去,很有启发。确实没有必要太强求model自己在类层次上的自足性,只要在接口上是自足的就足够。
0 请登录后投票
   发表时间:2004-08-21  
引用

领域对象也是一个接口,


明白了,这样确实可行。但要求领域对象是一个接口,在我们现在的做法中好像很困难,FormBean要实现领域对象接口也仍然有额外的编码。
0 请登录后投票
   发表时间:2004-08-27  
强烈支持webwork2
0 请登录后投票
   发表时间:2004-08-30  
就像你选择铁通和中国电信一样:D
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics