gpt4 book ai didi

repository - 存储库模式的替代方案?

转载 作者:行者123 更新时间:2023-12-04 04:32:16 24 4
gpt4 key购买 nike

人们对我大喊大叫,我应该总是 使用我已经做了很长一段时间的存储库模式......现在我想知道这种模式是否有任何体面的替代品?

最佳答案

好吧,有数据访问对象模式,但它通常位于存储库的顶部,用于包装复杂的查询,因此它们可以简单地作为单个方法调用。

Repository 为您的数据库提供了一个标准接口(interface),而 DAO 公开了标准查询,这就是为什么两者结合得这么好; DAO 将特定调用转发到存储库。当然,您当然可以选择不在您的 DAO 中使用存储库。您可以打开与数据库的连接并直接运行查询,或者使用表数据网关,但我认为大多数人喜欢 Repository 的原因是因为它比这两个选项更干净,尽管他们不应该大喊大叫你 :)

http://en.wikipedia.org/wiki/Data_access_object

In computer software, a data access object (DAO) is an object that provides an abstract interface to some type of database or persistence mechanism, providing some specific operations without exposing details of the database. It provides a mapping from application calls to the persistence layer. This isolation separates the concerns of what data accesses the application needs, in terms of domain-specific objects and data types (the public interface of the DAO), and how these needs can be satisfied with a specific DBMS, database schema, etc. (the implementation of the DAO). This design pattern is equally applicable to most programming languages, most types of software with persistence needs and most types of database, but it is traditionally associated with Java EE applications and with relational databases accessed via the JDBC API because of its origin in Sun Microsystems' best practice guidelines[1] ("Core J2EE Patterns") for that platform.

关于repository - 存储库模式的替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4980242/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com