DAO类在Web应用的3层架构中属于哪一层?

huangapple go评论68阅读模式
英文:

In which layer do DAO classes belong in a 3-tier architecture of a web app?

问题

让我们以一个BookDAO类为例,需要将列表填充满每本现存的书籍。依我之见,这个类属于最底层(数据访问层),但我也见过它作为中间层(业务逻辑)的一部分。以上哪个是正确的?

英文:

Let's consider a BookDAO class, for example, that needs to populate a list with every existing book. To my mind, this class belongs to the lowest layer (data access layer), but I've seen it as part of the middle layer (bussiness logic) too. Which of the above is correct?

答案1

得分: 1

  1. 将DAO保留在业务层会对系统的完整性产生负面影响。问题之一是数据的安全性。API通常与业务逻辑交互。混合业务逻辑和DAO会直接向API提供数据访问权限。
  2. 想象一种情况,您需要在业务逻辑的各种操作中使用相似的数据。将DAO保留在数据访问层中有助于在这两种操作中使用相同的数据检索。
英文:
  1. Keeping the DAO in the business layer has its own negative effect on the integrity of the system. One of the issues is the security of the data. APIs usually interact with the business logic. Mixing business logic and DAOs would give direct access to data to APIs.
  2. Imagine a situation where you need similar data for various operations in business logic. Keeping DAO in the data access layer would help in using the same data retrieval for both the operations.

huangapple
  • 本文由 发表于 2020年9月5日 04:51:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/63747891.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定