`
oojdon
  • 浏览: 40586 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

为关系数据库设计对象

阅读更多

 

这是DDD的原文,我认为最好的结论就是最后加粗部分,让模型和数据分开,而不是折中处理,这也是CQRS的本质。

Designing Objects for Relational Databases

The most common nonobject component of primarily object-oriented software systems is the relational database. This reality presents the usual problems of a mixture of paradigms (see Chapter 5). But the database is more intimately related to the object model than are most other components. The database is not just interacting with the objects; it is storing the persistent form of the data that makes up the objects themselves. A good deal has been written about the technical challenges of mapping objects to relational tables and effectively storing and retrieving them. A recent discussion can be found in Fowler 2002. There are reasonably refined tools for creating and managing mappings between the two. Apart from the technical concerns, this mismatch can have a significant impact on the object model.

There are three common cases:

  1. The database is primarily a repository for the objects.

  2. The database was designed for another system.

  3. The database is designed for this system but serves in roles other than object store.

When the database schema is being created specifically as a store for the objects, it is worth accepting some model limitations in order to keep the mapping very simple. Without other demands on schema design, the database can be structured to make aggregate integrity safer and more efficient as updates are made. Technically, the relational table design does not have to reflect the domain model. Mapping tools are sophisticated enough to bridge significant differences. The trouble is, multiple overlapping models are just too complicated. Many of the same arguments presented for MODEL-DRIVEN DESIGN—avoiding separate analysis and design models—apply to this mismatch. This does entail some sacrifice in the richness of the object model, and sometimes compromises have to be made in the database design (such as selective denormalization), but to do otherwise is to risk losing the tight coupling of model and implementation. This approach doesn't require a simplistic one-object/one-table mapping. Depending on the power of the mapping tool, some aggregation or composition of objects may be possible. But it is crucial that the mappings be transparent, easily understandable by inspecting the code or reading entries in the mapping tool.

  • When the database is being viewed as an object store, don't let the data model and the object model diverge far, regardless of the powers of the mapping tools. Sacrifice some richness of object relationships to keep close to the relational model. Compromise some formal relational standards, such as normalization, if it helps simplify the object mapping.

  • Processes outside the object system should not access such an object store. They could violate the invariants enforced by the objects. Also, their access will lock in the data model so that it is hard to change when the objects are refactored.

On the other hand, there are many cases in which the data comes from a legacy or external system that was never intended as a store of objects. In this situation, there are, in reality, two domain models coexisting in the same system. Chapter 14, "Maintaining Model Integrity," deals with this issue in depth. It may make sense to conform to the model implicit in the other system, or it may be better to make the model completely distinct.

Another reason for exceptions is performance. Quirky design changes may have to be introduced to solve execution speed problems.

 

But for the important common case of a relational database acting as the persistent form of an object-oriented domain, simple directness is best. A table row should contain an object, perhaps along with subsidiaries in an AGGREGATE. A foreign key in the table should translate to a reference to another ENTITY object. The necessity of sometimes deviating from this simple directness should not lead to total abandonment of the principle of simple mappings.

 

The UBIQUITOUS LANGUAGE can help tie the object and relational components together to a single model. The names and associations of elements in the objects should correspond meticulously to those of the relational tables. Although the power of some mapping tools may make this seem unnecessary, subtle differences in relationships will cause a lot of confusion.

 

The tradition of refactoring that has increasingly taken hold in the object world has not really affected relational database design much. What's more, serious data migration issues discourage frequent change. This may create a drag on the refactoring of the object model, but if the object model and the database model start to diverge, transparency can be lost quickly.

 

Finally, there are some reasons to go with a schema that is quite distinct from the object model, even when the database is being created specifically for your system. The database may also be used by other software that will not instantiate objects. The database may require little change, even while the behavior of the objects changes or evolves rapidly. Cutting the two loose from each other is a seductive path. It is often taken unintentionally, when the team fails to keep the database current with the model. If the separation is chosen consciously, it can result in a clean database schema—not an awkward one full of compromises conforming to last year's object model.

分享到:
评论

相关推荐

    面向对象数据库-对象型关系数据库-oracle

    Oracle8是Oracle首次引入面向对象技术的版本,它提供了一种结合面向对象和关系表达的解决方案,使得数据库设计更加紧凑有效。 Oracle数据库在全球范围内广泛应用,尤其在大型企业、Web站点和UNIX平台中占据重要地位...

    对象-关系数据库之间的映射.pdf

    面向对象设计与关系数据库设计之间的差异,源于两者理论基础的不同。面向对象设计强调耦合、聚合、封装等概念,关注数据和行为的封装;而关系数据库设计基于数学理论,专注于数据的存储和检索。这一差异导致在实际...

    关系数据库设计经验(总结经验)

    关系数据库设计是构建高效、稳定和可扩展的信息系统的关键步骤。它涉及到对业务需求的深入理解,以及如何将这些需求转化为合理的数据结构。以下是对数据库设计的一些重要考虑因素: 1. **需求分析**:在设计数据库...

    对象数据库系统与关系数据库间特性解析

    面向对象数据库系统(OODBS)和关系数据库系统(RDBMS)是两种主要的数据库管理系统,它们在设计理念和数据表示上存在显著差异。OODBS结合了数据库管理和面向对象编程的特性,使得数据和程序设计更加紧密集成。面向对象...

    UML在关系数据库设计中的应用

    在UML建模的各个阶段,从概念模型到逻辑模型再到物理模型的构建,均能为关系数据库设计提供关键的信息。在业务建模阶段,通过分析业务用例和业务对象模型,可以初步构建数据库的概念模型,其中包含了核心的数据实体...

    数据库设计,讲解业务实体对象到数据库表的映射关系。

    ### 数据库设计与业务实体对象到数据库表的映射关系 #### 一、数据库设计概述 数据库设计是在软件工程和信息系统领域中一个重要的环节,它涉及到如何有效地组织数据以满足特定业务需求。良好的数据库设计不仅能...

    对象-关系数据库之间的映射

    4. **实现关系**:对象模型中的关系在关系数据库中可能表现为连接表或嵌入数据。例如,一个`Student`类可能与`Class`类有一对多的关联,这可以通过在`Class`表中添加`StudentID`的外键字段来实现。 这些映射策略的...

    数据库设计文档.pdf

    数据库设计文档.pdf 本文档是人资信息管理系统数据库设计文档,主要对软件后台数据库的概念模型设计和物理模型设计作出了统一的规定,同时确定了每个表的数据字典构造。该文档是开发人员、测试人员编码及测试的重要...

    对象关系数据库对象关系数据库.ppt

    在传统的关系数据库中,数据被表示为表格,其中每一行代表一个元组,每一列代表一个属性,而这些属性通常都是原子性的,即不可再分的值。然而,在对象关系数据库中,这种限制被放宽,允许数据模型包含更复杂的结构。...

    面向对象的关系数据库设计 (2002年)

    针对面向对象技术和关系数据库的特点,将两者相结合,建立了对象关系数据库管理系统,既支持已经被广泛使用的SQL,不仅...文中还提出了对象关系数据库的设计方法和对象映射成关系数据库的方式,其方式简便,实用性强。

    对象数据库-第一次设计

    8. **设计原则**:在首次设计对象数据库时,我们需要考虑数据的组织方式、对象之间的关系、查询效率、扩展性等因素。合理的对象设计能够提高系统的可维护性和性能。 9. **迁移与集成**:如果从关系型数据库迁移到...

    基于对象关系数据库的移动对象数据库管理系统的研究

    ### 基于对象关系数据库的移动对象数据库管理系统的研究 #### 概述 本文探讨了一种新型的移动对象数据库管理系统(Moving Objects Database Management System, MOBDBMS),该系统基于对象关系数据库(Object-...

    使用UML进行面向对象分析与设计:第13章 数据库设计.pdf

    总结起来,本章内容深入探讨了如何使用UML进行面向对象分析与设计,同时考虑了数据库设计的特殊需求,为开发者提供了在实际项目中融合这两种方法的实用指导。通过理解和应用这些原则,开发者可以更有效地创建出既能...

    关系数据库模型设计

    采用面向对象的统一建模方法,如UML和Rational Rose,可以将软件分析设计与数据库设计紧密结合,提高开发效率,减少两者间的脱节。这种方法提供了一个全面而系统化的途径,对于现代软件工程来说具有显著的优势。

    数据库设计考试题目.docx

    10. 在关系数据库设计中,关系模式的设计是数据库设计中规律设计阶段的任务。 11. 在关系数据库中,关系代数运算是以代数运算为根底的运算,例如 Select 语句、Where 语句、Group by 语句等。 12. 在关系数据库中...

    OA 协同办公系统 数据库设计说明书(附数据库关系表)

    数据库可以分为多种类型,包括关系数据库、对象数据库、文档数据库等。 在 OA 协同办公系统中,使用的是关系数据库管理系统(RDBMS),它能够提供高效的数据存储和管理服务。关系数据库管理系统使用表(Table)来...

    支付交易平台数据库设计文档

    最后,数据库设计文档应详细记录每个表的字段说明、数据类型、约束条件、索引设计、触发器、存储过程等数据库对象的创建细节。这些内容都是数据库设计的关键组成部分,关系到数据库的整体性能、安全性和易用性。设计...

    关系数据库设计.docx

    关系数据库设计是软件项目中至关重要的一步,它构成了软件数据管理的基础。数据库设计的重要性往往被低估,但实际上,它对项目的成功起着决定性作用。在实际工作中,开发人员通常是数据库设计的主要参与者,尽管DBA...

Global site tag (gtag.js) - Google Analytics