🚀 Enjoying This Tutorial?
Subscribe to Ram N Java for more easy-to-follow software architecture and Java tutorials!
🔔 Subscribe NowWhat 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
Playerand addsclub. - Cricketer (Concrete Class): Inherits from
Playerand addsbatting_average. - Bowler (Concrete Class): Inherits from
Cricketerand addsbowling_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
Playerclass. - 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 |
No comments:
Post a Comment