Monday, 12 August 2013

Inheritance Mappers Design Pattern

Level Up Your Architecture Skills!

Subscribe to Ram N Java for clear, step-by-step enterprise design pattern tutorials!

Subscribe on YouTube

What is the Inheritance Mappers Design Pattern?

The Inheritance Mappers design pattern belongs to the Object-Relational Structural Patterns category in Enterprise Application Architecture.

Its primary purpose is to provide a structured way to organize database mappers that handle complex class inheritance hierarchies when transferring data between domain objects and relational database tables.

How Inheritance Mappers Work

In Object-Relational Mapping (ORM), mapping an inheritance hierarchy can follow strategies such as:

  • Single Table Inheritance: One table stores all classes in the hierarchy.
  • Class Table Inheritance: Each class in the hierarchy has its own corresponding table.
  • Concrete Table Inheritance: Only concrete classes have database tables.

Practical Hierarchy Example: Player Domain Model

Consider an inheritance structure:

  • Player (Superclass with name attribute)
  • Footballer extends Player (adds club attribute)
  • Cricketer extends Player (adds battingAverage attribute)
  • Bowler extends Cricketer (adds bowlingAverage attribute)

Using dedicated mappers (e.g., PlayerMapper, FootballerMapper, CricketerMapper, BowlerMapper), each mapper is responsible for:

  • Extracting values from domain objects and persisting them into appropriate database tables.
  • Reading rows from tables and reconstructing the corresponding domain objects (CRUD operations).

Recommended Tutorials from Ram N Java


Click here to watch in Youtube : https://www.youtube.com/watch?v=ClZo8rS7SCg

Click the below Image to Enlarge
Inheritance Mappers Design Pattern















See also:

  • All Design Patterns Links
  • 1 comment:

    1. Will you please post or provide me the java code for the same?

      ReplyDelete

    Tutorials