Repository模式

本文详细介绍了Repository模式的概念及其在软件架构中的应用。通过隔离domain层与数据持久层,该模式简化了复杂的业务逻辑处理,并增强了系统的可测试性。此外,文章还讨论了如何利用Repository模式来集中管理数据访问逻辑,从而提高代码的可读性和可维护性。
摘要由CSDN通过智能技术生成

望文生义:

Repository [rɪˈpɑzəˌtɔri]

释义:仓库,贮藏所,受人信托的人,心腹,亲信

Repository模式可以称为仓储模式,或资源库 

 

大师解释:

by Edward Hieatt and Rob Mee

Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects.

 

A system with a complex domain model often benefits from a layer, such as the one provided by Data Mapper, that isolates domain objects from details of the database access code. In such systems it can be worthwhile to build another layer of abstraction over the mapping layer where query construction code is concentrated. This becomes more important when there are a large number of domain classes or heavy querying. In these cases particularly, adding this layer helps minimize duplicate query logic.

A Repository mediates between the domain and data mapping layers, acting like an in-memory domain object collection. Client objects construct query specifications declaratively and submit them to Repository for satisfaction. Objects can be added to and removed from the Repository, as they can from a simple collection of objects, and the mapping code encapsulated by the Repository will carry out the appropriate operations behind the scenes. Conceptually, a Repository encapsulates the set of objects persisted in a data store and the operations performed over them, providing a more object-oriented view of the persistence layer. Repository also supports the objective of achieving a clean separation and one-way dependency between the domain and data mapping layers.

 

个人理解:

1,Repository主要是用来隔离domain与持久层, 就像是一个存储在内存中的domain对象集合 。

2, 方便测试,因为可以把针对数据库的持久化操作替换成内存中操作,解除对数据库依赖。

3, 数据存取集中放在一起,方便阅读和维护。

  如,现在要对数据存取加上缓存功能。只要统一修改Repository层即可。

 

参考:

http://martinfowler.com/eaaCatalog/repository.html

http://msdn.microsoft.com/en-us/library/gg416511(VS.98).aspx

转载于:https://www.cnblogs.com/season2009/archive/2012/05/17/2506527.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值