本文介绍了数据层的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个讨论与即将实施的新的应用程序的数据层的最佳途径同事中间。

I am in the middle of a "discussion" with a colleague about the best way to implement the data layer in a new application.

一种观点是,在数据层应该知道的业务对象(我们自己的类重新present一个实体)的,并能够以本机与该对象一起工作。

One viewpoint is that the data layer should be aware of business objects (our own classes that represent an entity), and be able to work with that object natively.

相对的观点是,数据层应该是对象无关,纯粹和处理简单的数据类型(字符串,布尔变量,日期等。)

The opposing viewpoint is that the data layer should be object-agnostic, and purely handle simple data types (strings, bools, dates, etc.)

我可以看到,这两种方法可能是有效的,但我自己的观点是,我preFER前者。这样,如果所述数据存储介质的变化,业务层不(一定)必须改变,以适应新的数据层。因此,这将是一件微不足道的小事,从一个SQL数据存储更改为一个序列化的XML文件系统存储。

I can see that both approaches may be valid, but my own viewpoint is that I prefer the former. That way, if the data storage medium changes, the business layer doesn't (necessarily) have to change to accommodate the new data layer. It would therefore be a trivial thing to change from a SQL data store to a serialized xml filesystem store.

来看我的同事的观点是,数据层不应该知道的对象定义,而且只要数据传递有关适当,那就足够了。

My colleague's point of view is that the data layer shouldn't have to know about object definitions, and that as long as the data is passed about appropriately, that is enough.

现在,我知道,这是一个已启动宗教战争的潜在的问题之一,但我AP preciate社会各界你如何对待这样的事情任何反馈。

Now, I know that this is one of those questions that has the potential to start a religious war, but I'd appreciate any feedback from the community on how you approach such things.

TIA

推荐答案

这真的取决于你对世界的看法 - 我以前是在非耦合阵营。该DAL那里只提供数据到BAL - 故事的结尾

It really depends on your view of the world - I used to be in the uncoupled camp. The DAL was only there to supply data to the BAL - end of story.

随着新兴技术,如LINQ to SQL和实体框架变得有点更受欢迎,那么DAL和BAL之间的界线已经模糊了一下。在L2S尤其是你的DAL是相当紧耦合的业务对象的对象模型有一个1-1映射到数据库字段。

With emerging technologies such as Linq to SQL and Entity Framework becoming a bit more popular, then the line between DAL and BAL have been blurred a bit. In L2S especially your DAL is quite tightly coupled to the Business objects as the object model has a 1-1 mapping to your database field.

就像软件开发任何没有正确或错误的答案。你需要了解你的需求和未来的质量要求,并从那里工作。我会在Dakhar涨势不再使用法拉利,我会揽胜在赛道日。

Like anything in software development there is no right or wrong answer. You need to understand your requirements and future requirments and work from there. I would no more use a Ferrari on the Dakhar rally as I would a Range Rover on a track day.

这篇关于数据层的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 12:25