关于struts里面ActionForm的immutable问题?

03-10-03 lyojbuilder
文章上说构造一个immutable对象

如下:

Setting an immutable value object

If you’re provided with an immutable value object that uses a bulk constructor,

then populating it boils down to this:

ArticleForm aForm = (ArticleForm) form;

ArticleBean aBean = new ArticleBean(

aForm.getArticleKey(),

aForm.getContributor(),

aForm.getCreator(),

aForm.getTitle(),

aForm.getContent()

);

然后就可以定义setter组:

divide and conquer:

ArticleForm aForm = (ArticleForm) form;

ArticleBean aBean = new ArticleBean();

aBean.setRecordHeader(

aForm.getArticleKey(),

aForm.getEditor());

aBean.setPeople(

aForm.getContributor(),

aForm.getCreator());

aBean.setText(

aForm.getTitle(),

aForm.getContent());

1.这个不变的类有什麽用处阿?2.这个setter组有什麽好处?

3.还有就是让ActionForm implements 一个生意方法有什麽好处?文章上说就可以这样操作:"articleModel.save((ArticleBean) form);"这是什麽意思?请指点

猜你喜欢