ORM对OO设计适得其反吗

ORM对OO设计适得其反吗

本文介绍了ORM对OO设计适得其反吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在面向对象的设计中,对象的设计被认为具有其特性和行为特征.

In OOD, design of an object is said to be characterized by its identity and behavior.

过去,我曾经使用过ORM,其主要目的围绕着存储/检索数据的能力.也就是说,ORM对象不是按行为设计的,而是按数据(即数据库表)设计的.案例和重点:许多ORM工具都带有指向数据库表和单击对象生成器的指针.

Having used ORM's in the past, the primary purpose, in my opinion, revolves around the ability to store/retrieve data. That is to say, ORM objects are not design by behavior, but rather data (i.e. database tables). Case and point: Many ORM tools come with a point-to-a-database-table-and-click-object-generator.

如果我认为物体不再具有行为特征,那么这将使物体的身份和责任变得混乱.随后,如果没有按职责定义对象,则可能有助于紧密耦合类和总体不良设计.

If objects are no longer characterized by behavior this will, in my opinion, muddy the identity and responsibility of the objects. Subsequently, if objects are not defined by a responsibility this could lend a hand to having tightly coupled classes and overall poor design.

此外,我认为在应用程序环境中,您将面临可伸缩性问题.

Furthermore, I would think that in an application setting, you would be heading towards scalability issues.

所以,我的问题是,您认为ORM是否会适得其反?潜在的问题可能是它们是否对应用程序开发适得其反.

So, my question is, do you think that ORM's are counterproductive to OO design? Perhaps the underlying question would be whether or not they are counterproductive to application development.

推荐答案

良好的数据库设计要求和良好的OO设计要求之间存在着一个众所周知的且常常被忽略的阻抗失配.大多数开发人员(以我的经验)或者不了解这种阻抗不匹配,或者不在乎.由于从数据库开始并从中生成对象(而不是从数据库中生成对象)更为常见,因此,是的,您最终将获得作为持久层很棒但从OO角度来看不是最佳的对象. (相反,从对象模型生成数据库,使我想want目结舌.)

There's a well-known and oft-ignored impedance mismatch between the requirements of good database design and the requirements of good OO design. Most developers (in my experience) either do not understand this impedance mismatch or do not care. Since it's more common to start with the database and generate the objects from it (rather than the reverse), then yes, you'll end up with objects that are great as a persistence layer but sub-optimal from an OO perspective. (The reverse, generating the database from the object model, makes me want to stab my eyes out.)

为什么从面向对象的角度来看它们不是最优的?因为由ORM生成的对象不是业务对象,即使具有部分类之类的对象也是如此.业务对象对行为进行建模. ORM对象模型持久性.我不会花十段时间来讨论这种区别. Rocky Lhotka 在他有关Business Objects的书和 CSLA框架.无论您喜欢还是使用CSLA,我都认为他的观点很可靠.

Why are they sub-optimal from an OO perspective? Because the objects produced by an ORM are not business objects, even with partial classes and the like. Business objects model behavior. ORM objects model persistence. I'm not going to spend ten paragraphs arguing this distinction. It's something Rocky Lhotka has covered quite well in his books on Business Objects and his CSLA framework. Whether or not you like or use CSLA, I think his arguments are solid ones.

这篇关于ORM对OO设计适得其反吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 04:42