存储库模式与Active Record模式相同吗? [英] Is Repository pattern as same as Active Record pattern?

查看:202
本文介绍了存储库模式与Active Record模式相同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

他们似乎是相似的。

解决方案

他们是不同的。



活动记录模式定义一个对象,将一行包裹在数据库表或视图中,封装数据访问,并在该数据上添加域逻辑。 >

在存储库模式中,所有的数据访问都放在一个单独的类中,并通过实例方法进行访问。对我来说,只是这样做是有益的,因为数据访问现在被封装在一个单独的类中,使业务对象能够实现业务。这将阻止数据访问和您通过Active Record获得的业务逻辑的不幸混合。



查看此链接以了解:



http://moleseyhill.com/ blog / 2009/07/13 / active-record-verses-repository /


They seems to be similar.

解决方案

They are different.

Active Record Pattern defines An object that wraps a row in a database table or view, encapsulates the data access, and adds domain logic on that data.

In the Repository pattern all of the data access is put in a separate class and is accessed via instance methods. To me, just doing this is beneficial, since data access is now encapsulated in a separate class, leaving the business object to get on with business. This should stop the unfortunate mixing of data access and business logic you tend to get with Active Record.

Check this link for understanding:

http://moleseyhill.com/blog/2009/07/13/active-record-verses-repository/

这篇关于存储库模式与Active Record模式相同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆