h.Class Table Inheritance

  1. Motivation
    1. Represents an inheritance hierarchy of classes with one table for each class.
  2. Summary
    1. The straightforward thing about Class Table Inheritance is that it has one table per class in the domain model. The fields in the domain class map directly to fields in the corresponding tables.
    2. One issue is how to link the corresponding rows of the database tables. A possible solution is to use a common primary key value.
    3. The biggest implementation issue with Class Table Inheritance is how to bring the data back from multiple tables in an efficient manner. Obviously, making a call for each table isn't good since you have multiple calls to the database. You can avoid this by doing a join across the various component tables; however, joins for more than three or four tables tend to be slow because of the way databases do their optimizations. 
    4. Today there are several ORM solutions (like EF) that provides out of the box support for such mapping 

  3. When to Use
    1. Creating domain model based on some ORM solutions like EF.
  4. Related Patterns
    1. Single Table Inheritance
    2. Concrete Table Inheritance
  5. Related Technologies 
    1. Entity Framework
  6. Specific Considerations 
    1. Pros and Cons
      1. Pros
        1. All columns are relevant for every row so tables are easier to understand and don't waste space. 
        2. The relationship between the domain model and the database is very straightforward. 
      2. Cons
        1. You need to touch multiple tables to load an object, which means a join or multiple queries and sewing in memory. 
        2. Any refactoring of fields up or down the hierarchy causes database changes. 
        3. The supertype tables may become a bottleneck because they have to be accessed frequently. 
        4. The high normalization may make it hard to understand for ad hoc queries. 
        5. You don't have to choose just one inheritance mapping pattern for one class hierarchy
  7. References
    1. http://martinfowler.com/eaaCatalog/classTableInheritance.html