Sunday, 11 August 2013

Concrete Table Inheritance Design Pattern

🚀 Enjoying This Tutorial?

Subscribe to Ram N Java for more easy-to-follow software architecture and Java tutorials!

🔔 Subscribe Now

What is Concrete Table Inheritance?

The Concrete Table Inheritance pattern is an object-relational structural pattern from Martin Fowler's Patterns of Enterprise Application Architecture. It represents an inheritance hierarchy by creating exactly one database table for each concrete class.

The Problem: Mapping Inheritance to Relational Databases

Relational databases do not have a native concept of object-oriented inheritance. When you have classes extending one another, you need a strategy to map those classes into tables and columns.

Step-by-Step Example

Let's look at an inheritance hierarchy:

  • Player (Abstract Superclass): Contains the attribute name.
  • Footballer (Concrete Class): Inherits from Player and adds club.
  • Cricketer (Concrete Class): Inherits from Player and adds batting_average.
  • Bowler (Concrete Class): Inherits from Cricketer and adds bowling_average.

Database Table Design:

  • footballers table: name, club
  • cricketers table: name, batting_average
  • bowlers table: name, batting_average, bowling_average

Key Takeaways

  • No table is created for the abstract Player class.
  • Each concrete table contains all inherited and declared fields.
  • Reading single entities is fast because no JOIN operations across parent tables are required.

Related Videos to Watch Next


Click here to watch in Youtube : https://www.youtube.com/watch?v=ruB-8D7Isg0

Click the below Image to Enlarge
Concrete Table Inheritance Design Pattern














See also:

  • All Design Patterns Links
  • No comments:

    Post a Comment

    Tutorials