Saturday, 10 August 2013

Row Data Gateway Design Pattern

Master Software Architecture & Design Patterns!

Subscribe to Ram N Java for beginner-friendly, practical software engineering guides!

🔔 Subscribe to Our Channel

What is the Row Data Gateway Pattern?

The Row Data Gateway design pattern belongs to the data source architectural patterns in enterprise application architecture. In simple terms, a Row Data Gateway is an object that acts as a gateway to a single record in a data source.

Under this pattern, there is exactly one instance per database row. It gives your application objects that look exactly like records in your database table, but allows them to be accessed using the standard idioms and mechanisms of your programming language.

Real-World Example: Person Table Mapping

Consider a Person database table with columns like ID, Name, Age, and Gender:

  • Table Records: Suppose row 1 contains Joe (Age: 23, Male) and row 2 contains Gopi (Age: 28, Male).
  • Gateway Objects: The system creates a dedicated Person gateway object for each individual row. Object 1 maps directly to Joe's row, and Object 2 maps directly to Gopi's row.
  • Natural Object Access: Business logic interacts directly with fields and methods on these objects rather than dealing with raw SQL queries or database cursors.

How Does it Work? (Finder & Gateway)

The pattern often pairs the gateway class with a Finder:

  • Client Request: The client uses a PersonFinder and calls a method like find(id).
  • Query Execution: The finder executes the underlying database query (e.g., SELECT * FROM Person WHERE ID = 1).
  • Instantiation: From the returned record set, the finder instantiates the specific Person Row Data Gateway object populated with that row's data and returns it to the caller.

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

Click the below Image to Enlarge
Row Data Gateway Design Pattern



See also:

  • All Design Patterns Links
  • No comments:

    Post a Comment

    Tutorials