Showing posts with label ORM Patterns. Show all posts
Showing posts with label ORM Patterns. Show all posts

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
  • Sunday, 11 August 2013

    Class Table Inheritance Design Pattern

    Master Enterprise Architecture Patterns!

    Subscribe to Ram N Java for in-depth, easy-to-follow database and software design pattern tutorials!

    Subscribe on YouTube

    What 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 players table (stores name).
    • Footballer Class: Maps to the footballers table (stores club).
    • Cricketer Class: Maps to the cricketers table (stores batting_average).
    • Bowler Class: Maps to the bowlers table (stores bowling_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















    See also:

  • All Design Patterns Links
  • Tutorials