Showing posts with label Data Mapper. Show all posts
Showing posts with label Data Mapper. Show all posts

Saturday, 24 August 2013

Data Source Architectural Patterns

🚀 Master Enterprise Java & Software Architecture!

Subscribe to Ram N Java for clean, visual, and beginner-friendly programming tutorials!

🔔 Subscribe Now

What are Data Source Architectural Patterns?

Connecting enterprise business logic to relational database systems is one of the most critical aspects of application design. If data access code is scattered haphazardly across your application, changes to the database structure quickly break business rules.

In Martin Fowler’s classic work, Patterns of Enterprise Application Architecture (PofEAA), Data Source Architectural Patterns provide proven architectural strategies to isolate, organize, and manage the communication between in-memory business objects and database tables.

The 4 Core Data Source Architectural Patterns

Martin Fowler categorizes four core patterns that define how your application interfaces with a relational database:

1. Table Data Gateway

An object that acts as a Gateway to an entire database table. A single instance handles all rows in the table, providing methods to query, insert, update, and delete rows (e.g., returning RecordSets or generic collections).

2. Row Data Gateway

An object that acts as a Gateway to a single row or record in a data source. One instance corresponds to exactly one row in the table, encapsulating data access logic for that record while keeping business logic separate.

3. Active Record

An object that wraps a single row in a database table or view, encapsulates the database access, and adds domain business logic directly on that data. It combines both data persistence and business rules within the same class.

4. Data Mapper

A layer of mappers that moves data between objects and a database while keeping them completely independent of each other and the mapper itself. This pattern provides complete decoupling, allowing the in-memory domain model and database schema to evolve independently.

How to Choose the Right Pattern?

  • Simple Applications & CRUD: Table Data Gateway or Row Data Gateway are excellent when coupled with Transaction Script or Table Module patterns.
  • Medium Complexity: Active Record is ideal when business logic is relatively simple and closely follows database tables.
  • Complex Domain Logic: Data Mapper is the best choice when using a rich Domain Model, ensuring domain entities remain pure and untainted by persistence code.

Recommended Design Pattern Tutorials:


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

Click the below Image to Enlarge
Data Source Architectural  Patterns















See also:

  • All Design Patterns Links
  • Tutorials