Object-Relational Structural Patterns

Single Table Inheritance

Represents an inheritance hierarchy of classes as a single table that has columns for all the fields of the various classes.

These are the strengths of Single Table Inheritance:

  • There‘s only a single table to worry about on the database.
  • There are no joins in retrieving data.
  • Any refactoring that pushes fields up or down the hierarchy doesn‘t require you to change the database.

The weaknesses of Single Table Inheritance are

  • Fields are sometimes relevant and sometimes not, which can be confusing to people using the tables directly.
  • Columns used only by some subclasses lead to wasted space in the database. How much this is actually a problem depends on the specific data characteristics and how well the database compresses empty columns. Oracle, for example, is very efficient
    in trimming wasted space, particularly if you keep your optional columns to the right side of the database table. Each database has its own tricks for this.
  • The single table may end up being too large, with many indexes and frequent locking, which may hurt performance. You can avoid this by having separate index tables that either list keys of rows that have a certain property or that copy a
    subset of fields relevant to an index.
  • You only have a single namespace for fields, so you have to be sure that you don‘t use the same name for different fields. Compound names with the name of the class as a prefix or suffix help here.

Class Table Inheritance

Represents an inheritance hierarchy of classes with one table for each class.

The strengths of Class Table Inheritance are

  • All columns are relevant for every row so tables are easier to understand and don‘t waste space.
  • The relationship between the domain model and the database is very straightforward.

The weaknesses of Class Table Inheritance are

  • You need to touch multiple tables to load an object, which means a join or multiple queries and sewing in memory.
  • Any refactoring of fields up or down the hierarchy causes database changes.
  • The supertype tables may become a bottleneck because they have to be accessed frequently.
  • The high normalization may make it hard to understand for ad hoc queries.

Concrete Table Inheritance

Represents an inheritance hierarchy of classes with one table per concrete class in the hierarchy.

The strengths of Concrete Table Inheritance are:

  • Each table is self-contained and has no irrelevant fields. As a result it makes good sense when used by other applications that aren‘t using the objects.
  • There are no joins to do when reading the data from the concrete mappers.
  • Each table is accessed only when that class is accessed, which can spread the access load.

The weaknesses of Concrete Table Inheritance are:

  • Primary keys can be difficult to handle.
  • You can‘t enforce database relationships to abstract classes.
  • If the fields on the domain classes are pushed up or down the hierarchy, you have to alter the table definitions. You don‘t have to do as much alteration as with
    Class Table Inheritance (285), but you can‘t ignore this as you can with
    Single Table Inheritance (278).
  • If a superclass field changes, you need to change each table that has this field because the superclass fields are duplicated across the tables.
  • A find on the superclass forces you to check all the tables, which leads to multiple database accesses (or a weird join).

Object-Relational Structural Patterns

时间: 2024-10-11 23:13:12

Object-Relational Structural Patterns的相关文章

ORM(Object Relational Mapping)框架

ORM(Object Relational Mapping)框架 ORM(Object Relational Mapping)框架采用元数据来描述对象一关系映射细节,元数据一般采用XML格式,并且存放在专门的对象一映射文件中. 只要提供了持久化类与表的映射关系,ORM框架在运行时就能参照映射文件的信息,把对象持久化到数据库中.当前ORM框架主要有三种:Hibernate(Nhibernate),iBATIS,EclipseLink. 框架整体介绍 说道这里,其实这个ORM框架仍然存着这很大的问题

一:ORM关系对象映射(Object Relational Mapping,简称ORM)

狼来的日子里! 奋发博取 10)django-ORM(创建,字段类型,字段参数) 一:ORM关系对象映射(Object Relational Mapping,简称ORM) ORM分两种: DB first 先在数据库中创建数据库表等 Code first 先创建类,然后根据类创建数据表等.django中遵循 Code Frist 的原则,即:根据代码中定义的类来自动生成数据库表. 二:Django ORM创建 1)创建类 创建的类必须继承models.Model,在数据库中自动创建表名为:app

Object Relational Mapping(ORM)

Object Relational Mapping(ORM) ORM介绍 ORM概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术. 简单的说,ORM是通过使用描述对象和数据库之间映射的元数据,将程序中的对象自动持久化到关系数据库中. ORM在业务逻辑层和数据库层之间充当了桥梁的作用. ORM由来 让我们从O/R开始.字母O起源于"对象"(Object),而R则来自于"关系&qu

ORM(Object Relational Mapping)

ORM的简绍 对象关系映射(英语:(Object Relational Mapping,简称ORM,或O/RM,或O/R mapping),是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换 .从效果上说,它其实是创建了一个可在编程语言里使用的--"虚拟对象数据库". 面向对象是从软件工程基本原则(如耦合.聚合.封装)的基础上发展起来的,而关系数据库则是从数学理论发展而来的,两套理论存在显著的区别.为了解决这个不匹配的现象,对象关系映射技术应运而生. 对象关系映射(

django关系对象映射(Object Relational Mapping,简称ORM)

Model 创建数据库,设计表结构和字段 django中遵循 Code Frist 的原则,即:根据代码中定义的类来自动生成数据库表 from django.db import models class userinfo(models.Model): name = models.CharField(max_length=30) email = models.EmailField() memo = models.TextField() 连表结构 一对多:models.ForeignKey(其他表)

python—day60 Object Relational Mapping(ORM) ORM连表查询 ORM进阶

import os if __name__ == '__main__': # 指定当前py脚本需要加载的Django项目配置信息 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BookManageSystem.settings') # 启动Django项目 import django django.setup() from app01 import models # 多对多操作 # 1.create # 做了两件事情 # 1.创建了一个名为ke

Learning JavaScript Design Patterns -- A book by Addy Osmani

Learning JavaScript Design Patterns A book by Addy Osmani Volume 1.6.2 Tweet Copyright © Addy Osmani 2015. Learning JavaScript Design Patterns is released under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 unported license. It

Design Pattern----Structural Patterns

Structural Patterns(结构模式)主要关注于如何将一些小的类或对象组织成一个大的结构.Structural Patterns分为Structural Class Patterns(结构类模式)和Structural Object Patterns(结构对象模式),Structural Class Patterns用一些面向对象的继承和封装性质将一些接口和对接口的实现组织起来,使得接口的外部调用和接口的内部实现独立:而Structural Object Patterns描述的却是将

Design patterns in Spring Framework

This article is the 4th about design patterns used in Spring framework. It'll present new 3 patterns implemented in this framework. At the begin, we'll discover 2 patterns belonging to the family of structural patterns: adapter and decorator. At the