EJB依赖于FacesContext是不好的设计吗? [英] Is it a bad design for a EJB to depend on FacesContext?

查看:124
本文介绍了EJB依赖于FacesContext是不好的设计吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,通过参数将 context.getExternalContext()。getRequestLocale()传递给EJB,而不是使用import和getCurrentInstance从内部更好EJB?

  import javax.faces.context.FacesContext; 
FacesContext.getCurrentInstance()

(我是新的Web开发)

解决方案

如果您将软件系统视为三层架构,那么 FacesContext (它是JSF框架的一部分)属于应用层的表示层和 EJB



一般来说,较低层(应用程序)取决于较高层(Presentation),软件设计不好。它导致高耦合,低内聚力,因此总体上软件质量差。



总而言之,最好是通过参数传递值而不是访问 FacesContext EJB


Would it be better, for example, to pass context.getExternalContext().getRequestLocale() to the EJB by parameter, instead of using an import and getCurrentInstance from inside the EJB?

import javax.faces.context.FacesContext;
FacesContext.getCurrentInstance()

(I'm new to web development)

解决方案

If you think of your software system as a three layer architecture then the FacesContext (which is part of the JSF framework) belongs to the presentation layer and the EJB to the application layer.

In general it's bad software design when a lower layer (application) depending on higher layer (Presentation). It leads to high coupling, low cohesion and therefore overall to poor software quality.

To sum it up, it would be better to pass the values by parameter instead of accessing the FacesContext from a EJB.

这篇关于EJB依赖于FacesContext是不好的设计吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆