Master Enterprise Architecture Patterns!
Subscribe to Ram N Java for in-depth, easy-to-follow database and software design pattern tutorials!
Subscribe on YouTubeWhat is the Class Table Inheritance Pattern?
The Class Table Inheritance pattern is an Object-Relational Structural Pattern used in Enterprise Application Architecture.
Since relational databases do not natively support inheritance, this pattern represents an inheritance hierarchy of classes by mapping one database table for each class in the hierarchy.
How Class Table Inheritance Works
Each class in your domain model maps directly to its own database table containing only the fields unique to that class:
- Player Class (Superclass): Maps to the
playerstable (storesname). - Footballer Class: Maps to the
footballerstable (storesclub). - Cricketer Class: Maps to the
cricketerstable (storesbatting_average). - Bowler Class: Maps to the
bowlerstable (storesbowling_average).
Linking Rows Across Tables
To link corresponding records across parent and child tables, a common Primary Key (foreign key pointing to parent table) is used:
- Saving Data: An instance of a child class requires inserting rows into both the parent table and the child table.
- Reading Data: Querying full object details requires joining the parent and child tables using their shared primary key.
Recommended Tutorials from Ram N Java
Click here to watch in Youtube : https://www.youtube.com/watch?v=UatcHToJF00
Click the below Image to Enlarge
| Class Table Inheritance Design Pattern |
No comments:
Post a Comment