英文:
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
- 将DAO保留在业务层会对系统的完整性产生负面影响。问题之一是数据的安全性。API通常与业务逻辑交互。混合业务逻辑和DAO会直接向API提供数据访问权限。
- 想象一种情况,您需要在业务逻辑的各种操作中使用相似的数据。将DAO保留在数据访问层中有助于在这两种操作中使用相同的数据检索。
英文:
- 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.
- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论