Repository模式与"智能"业务对象 [英] Repository pattern vs. "smart" business objects

查看:105
本文介绍了Repository模式与"智能"业务对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到两个主要的思想的学校,当涉及到.NET上(的WinForms,WPF,ASP.NET)建立规模更大的企业级应用。

I see two main "schools of thoughts" when it comes to creating larger-scale enterprise-wide apps on .NET (Winforms, WPF, ASP.NET).

有些人用它使用一个知道如何获取,插入,更新和删除对象存储库的库模式。这些对象是相当愚蠢的,因为它们不一定包含一大堆逻辑的 - 例如,他们或多或少的数据传输对象。

Some folks use the "repository pattern" which uses a repository that knows how to fetch, insert, update and delete objects. Those objects are rather "dumb" in that they don't necessarily contain a whole lot of logic - e.g. they're more or less data-transfer objects.

另一阵营使用我所说的那些知道如何加载自己的聪明的业务对象,他们通常有一个保存(),可能update()或者甚至删除()方法。在这里,你真的不需要任何存储库 - 对象本身知道如何加载和保存自己

The other camp uses what I call "smart" business objects that know how to load themselves, and they typically have a Save(), possibly Update() or even Delete() method. Here you really don't need any repository - the objects themselves know how to load and save themselves.

大问题是:这你使用或preFER?为什么?

Big question is: which do you use or prefer? And why?

你用在所有的应用程序相同的方法,或者你有什么特别的标准时选择了另一种方式?如果是这样的 - 那些是什么标准

Do you use the same approach in all your apps, or do you have any particular criteria when to choose one approach over the other? If so - what are those criteria?

我并不想在这里开始火焰战争 - 只是试图找出大家都认为这件事,你的意见是什么,以及为什么你使用一个(或两个)模式比其他

I'm not trying to start a flame-war here - just trying to find out what everyone thinks about this and what your opinion is, and why you use one (or both) patterns over the other.

感谢任何建设性的意见!

Thanks for any constructive input!

推荐答案

我用的,因为单一职责原则的存储库模式。我不希望每个对象必须知道如何保存,更新,删除自身,当这可以通过一个单一的通用信息库来处理

I use the repository pattern because of the Single Responsibility Principle. I don't want each individual object to have to know how to save, update, delete itself, when this can be handled by one single generic repository

这篇关于Repository模式与"智能"业务对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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