简体   繁体   English

我是否处于分层防泄漏模式? 我该怎么办?

[英]Am I in tier leakage anti pattern? What should I do?

I was asked to add a module to existing system. 我被要求向现有系统添加模块。 While studying the structure, I found something 'weird'. 在研究结构时,我发现了一些“怪异”的东西。 The system is struts1 based. 该系统基于struts1。

In some jsp, I found there are some DAO call to return entity object. 在一些jsp中,我发现有一些DAO调用来返回实体对象。 In most JSP pages, there is a <app:validate> tag, which would make call to DAO to check access rights, and would redirect to the login page if not permitted. 在大多数JSP页面中,都有一个<app:validate>标记,该标记将调用DAO来检查访问权限,并且如果不允许,将重定向到登录页面。 There is an accessDA object, but it does more than data fetching, it also does some access right checking. 有一个accessDA对象,但是它不仅可以进行数据获取,而且还可以进行一些访问权限检查。

My questions are: 我的问题是:

  1. Does calling out DAO in view lead to tier leakage? 调出DAO是否会导致层泄漏?
  2. Is the app tag implementation a good practise (or should it do checking at action class instead of at view)? 应用代码实现是一种好的做法(还是应该在操作类而不是视图中进行检查)?
  3. Is the accessDA too fat? accessDA太胖了吗?
  4. Should my new module follow the existing structure? 我的新模块应该遵循现有结构吗?

In a typical MVC usage, there should be a clear Separation of Concerns . 在典型的MVC用法中,应该有明确的关注点分离 Meaning, Model, View and Controller part should be decoupled. 含义,模型,视图和控制器部分应解耦。 Let me answer your questions 我来回答你的问题

1. calling out DAO is it lead to tier leakage 1.喊出DAO是否会导致层泄漏

Yes. 是。 Ideally and DAO calls should be there in action/handler class. 理想情况下,DAO调用应该在操作/处理程序类中进行。 The data thus obtained is put in request/session to be picked up later by view rendering tier. 这样获得的数据被放入请求/会话中,以便稍后由视图呈现层获取。

2.the app tag implementation, is it a good practise?(or should it do checking at action cla ss instead of at view.) 2,应用标签的实现,这是一个好习惯吗?(还是应该在动作上进行检查而不是查看)

There should not be a DAO calls on every access right check. 每次访问权限检查都不应有DAO调用。 The access rights should be cached as the user login and same should be checked on subsequent requests using the aforementioned tag. 访问权限应作为用户登录名进行缓存,并应使用上述标记在后续请求中进行检查。 So here, not direct violation though but not a good practice. 所以在这里,虽然不是直接违规,但不是一个好习惯。

3.is it the accessDA too fat? 3.accessDA太胖了吗?

Yes. 是。 It appears so. 看起来是这样。

4.should my new module follow the existing structure? 4.我的新模块应该遵循现有结构吗?

Having made the above observations, I would advice against it. 作出上述观察后,我建议不要这样做。

1) IMO yes, but: it's not a leaky abstraction as such, precisely because it's in a tag. 1)海事组织(IMO)是的,但是: 并不是这样的泄漏抽象,正是因为它在标签中。 Tags exist to abstract implementation details from the view. 存在标记以从视图中抽象实现细节。 It's also arguable that doing the access lookup in the action makes the action responsible for something that's relevant only to the view layer. 也有争议的是,在操作中进行访问查找会使操作对仅与视图层相关的内容负责。

Another issue with encapsulating the data access in the tag itself is that if there are many uses of the tag on the page there may be more data access than necessary, slowing response time. 将数据访问封装在标签本身中的另一个问题是,如果页面上使用标签的次数很多,则可能需要的数据访问量过多,从而降低了响应时间。 A clever tag could mitigate this by caching values, or caching may be implemented at a deeper level. 聪明的标签可以通过缓存值来减轻这种情况,或者可以在更深层次上实现缓存。

2) A tag like that should be acting against the current user object, which should have encapsulated the user's rights already (probably on login). 2)像这样的标记应该对当前用户对象起作用,该对象应该已经封装了用户的权限(可能在登录时)。 That said, it may not be sufficient to use cached values to determine access rights if those rights may change during a user's session. 也就是说,如果高速缓存的值可以在用户会话期间更改,则使用高速缓存的值来确定访问权限可能还不够。

3) I don't know; 3)我不知道; without knowing more details IMO that's impossible to answer. 在不知道更多细节的情况下,IMO无法回答。

4) Depends. 4)取决于。 Doing the same thing multiple ways can lead maintenance nightmares. 多种方式做同一件事可能导致维护方面的噩梦。

If there's an effort to re-structure the application according to best practices, then yes, new development should follow better patterns. 如果要根据最佳实践重新构建应用程序,那么可以,新开发应遵循更好的模式。 If there isn't, IMO it's more confusing to introduce multiple ways of doing the same thing, and makes it more difficult for those who follow because they then need to decide which way to do something, determine if there's a functional difference between the different ways, and so on. 如果没有的话,IMO会引入多种做同一件事的方式,这会使人更加困惑,并且使追随者变得更加困难,因为他们随后需要决定做某事的方式,确定不同事物之间是否存在功能上的差异方式等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在Java中正确理解内存泄漏吗 - Am I understanding Memory Leakage correctly in Java 如何避免BroadcastReceiver泄漏 - How do I avoid BroadcastReceiver leakage 我在想什么OOD设计模式? - What OOD design pattern am I thinking of? 当我在 Java 中读取 API 时,我在字符串中使用 ÃŽ 代替 Î。 我该怎么办? - When I am reading a API in java I get ÃŽ in place of Î in a string. What should I do? 我应该更改哪种模式进行验证? - What should I change the pattern to validate? 如果我以有效的方式找到一个大数字的阶乘,但我仍然得到 TLE,我该怎么办? - What should I do if I am finding the factorial of a big Number in an efficient way still I am getting a TLE? 我正在尝试给我的扫描仪打电话,但它不起作用。 我该怎么办? - I am trying to call my Scanner but its not working. What should i do? 当我执行代码时,仅生成公钥而不生成私钥,那该怎么办? - when I am executing the code only public key is generated but not the private key ,so what should I do? 我正在尝试实现自己的HashSet,但我不知道应该返回什么iterator()方法? - I am trying to implement my own HashSet and I do not know what iterator() method should return? 我试图递归地对我的普通树做一个插入方法,我该怎么办? - i am trying to make an insert method recursively to my general tree what should i do?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM