Skip to content

Commit 1c070db

Browse files
committed
sample classes and tests
1 parent 55d3337 commit 1c070db

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

table-inheritance/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Table Inheritance
2+
3+
**Category:** Data Access Pattern, Structural Pattern
4+
5+
**Tags:** Decoupling, Inheritance, Polymorphism, Object Mapping, Persistence, Data Transformation
6+
7+
---
8+
9+
## Intent
10+
The **Table Inheritance** pattern models a class hierarchy in a relational database. Each class in the hierarchy is mapped to its own table, and the tables are linked through foreign keys representing the inheritance structure.
11+
12+
This pattern is particularly useful for organizing complex data models when different subclasses have distinct properties that need to be stored in separate tables.
13+
14+
---
15+
16+
## Real-World Example
17+
Imagine a vehicle management system with a `Vehicle` superclass and subclasses such as `Car` and `Truck`.
18+
- The `Vehicle` table stores attributes common to all vehicles.
19+
- The subclass tables (`Car` and `Truck`) store attributes specific to each subclass.
20+
21+
---
22+
23+
## Database Schema
24+
25+
### Vehicle Table
26+
| Column | Description |
27+
|--------|-------------------------------------|
28+
| id | Primary key |
29+
| make | The make of the vehicle |
30+
| model | The model of the vehicle |
31+
| year | The manufacturing year of the vehicle |
32+
33+
### Car Table
34+
| Column | Description |
35+
|------------------|-------------------------------------|
36+
| id | Foreign key referencing `Vehicle(id)` |
37+
| numberOfDoors | Number of doors in the car |
38+
39+
### Truck Table
40+
| Column | Description |
41+
|-------------------|-------------------------------------|
42+
| id | Foreign key referencing `Vehicle(id)` |
43+
| payloadCapacity | Payload capacity of the truck |
44+
45+
---
46+
47+
## Benefits
48+
- Decouples subclasses into their own tables for easier management and scalability.
49+
- Allows for flexibility in subclass-specific attributes without altering the base table.
50+
51+
---

0 commit comments

Comments
 (0)