gpt4 book ai didi

java - JSF 注销页面 - 最佳实践 : is it correct to use one common bean?

转载 作者:行者123 更新时间:2023-11-29 08:04:31 24 4
gpt4 key购买 nike

为应用程序通用的操作使用 commonBean 是否正确/最佳实践?在我的例子中,这将是一个注销函数,用于清除 session bean 的记录值。

我的一位同事告诉我每个 View 只能使用一个 Controller bean,但是在多个 bean 中复制相同的方法似乎是一种浪费。

最佳答案

您的同事将 View 和 Controller 的分离称为纯 MVC 模式中松散定义的原则。 JSF 应用程序中的托管 Bean 非常适合 Controller 的角色,但是,由于您已经陈述的原因,这不应被视为硬性规定。

我引用企业应用程序架构模式中的 Martin Fowler 的话:

As I said, the value of MVC lies in its two separations. Of these are the separation of presentation and model is one of the most important design principles in software, and the only time you shouldn't follow it is in very simple systems where the model has no real behavior in it anyway. As soon as you get some nonvisual logic you should apply the separation. Unfortunately, a lot of UI frameworks make it difficult, and those that don't are often taught without a separation.

The separation of view and controller is less important, so I'd only recommend doing it when it is really helpful. For rich-client systems, that ends up being hardly ever, although it is common in Web front ends where the controller is separated out. Most of the patterns on Web design here are based on that principle.

从本质上讲,Fowler 指出将 View 绑定(bind)到 Controller 并不像将模型绑定(bind)到 View 那么重要,因此如果有帮助的话,跨 View 使用 Controller 或每个 View 使用多个 Controller 当然是可以接受的。

关于java - JSF 注销页面 - 最佳实践 : is it correct to use one common bean?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12157711/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com