architect-handbook

Software Architect Handbook

View on GitHub

Concrete Table Inheritance

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

Overview

Take each object in memory and map it to a single database row. With Concrete Table Inheritance, there’s a table for each concrete class in the inheritance hierarchy.

Most people think of it as a leaf oriented since you usually have one table per leaf class in a hierarchy. Strictly, however, a concrete class that isn’t a leaf ususally gets a table as well.

How It Works

Concrete Table Inheritance uses one database table for each concrete class in the hierarchy. Each table contains columns for the concrete class and all it ancestors, so any fields in a superclass are duplicated across the tables of the subclasses.

The basic behavior uses Inheritance Mappers. It’s important to ensure that keys are unique not just to a table but to all the tables from a hierarchy.

A classic example of where you need this is if you have a collectio nof players and you’re using Identity Field with table-wide keys. If keys can be duplicated between the tables that map the concrete classes, you’ll get multiple rows for a particular key value.

When to Use It

Class Table Inheritance, Single Table Inheritance and Concrete Table Inheritance are the three alternatives to consider for inheritance mapping.

Advantages

Disadvantages