Is it a bad design for a EJB to depend on FacesContext?

你离开我真会死。 提交于 2019-12-13 02:58:46

问题


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)


回答1:


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.



来源:https://stackoverflow.com/questions/37554150/is-it-a-bad-design-for-a-ejb-to-depend-on-facescontext

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!