Showing posts with label Table Module. Show all posts
Showing posts with label Table Module. Show all posts

Saturday, 24 August 2013

Table Module Design Pattern vs Transaction Script Pattern

🚀 Master Enterprise Java & Architecture Patterns!

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

🔔 Subscribe Now

Table Module vs Transaction Script: Key Differences Explained

When designing the domain layer of enterprise applications, two popular and accessible patterns often come up: Table Module Pattern and Transaction Script Pattern. Both are documented in Martin Fowler's Patterns of Enterprise Application Architecture (PofEAA), but they organize business logic in very different ways.

1. What is the Transaction Script Pattern?

The Transaction Script Pattern organizes business logic into dedicated procedures (or scripts) where each procedure handles a single request from the presentation tier.

  • Request-Oriented: Each user action triggers a dedicated script (e.g., calculateContractRevenue()).
  • Procedural Style: The code executes sequentially—fetching data from the database, performing calculations, and writing changes back.
  • Best Suited For: Applications with simple business logic and minimal complex domain rules.

2. What is the Table Module Pattern?

The Table Module Pattern structures business logic around tabular data. A single class instance contains all the business logic for an entire database table or view.

  • Table-Centric: Instead of creating one object per database record, you create one module per database table (e.g., ContractTableModule).
  • Set-Based Processing: It operates directly on collections or record sets (like DataSets) returned by queries.
  • Centralized Logic: Business rules related to a specific table live in one shared place, preventing duplicated logic across scripts.

Comparison: Table Module vs Transaction Script

  • Code Duplication: Transaction Scripts often risk duplicate code across multiple procedures, whereas Table Modules consolidate table-level logic in one place.
  • Data Organization: Transaction Scripts focus on actions/use-cases, while Table Modules focus on relational database tables.
  • Maintainability: Table Module scales better when multiple use cases need to perform calculations or operations on the same table data.

Recommended Design Pattern Tutorials:


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

Click the below Image to Enlarge
Table Module Design Pattern vs Transaction Script Pattern



Table Module Design Pattern vs Transaction Script Pattern

























See also:

  • All Design Patterns Links
  • Table Module Design Pattern

    🚀 Master Enterprise Java & Architecture Patterns!

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

    🔔 Subscribe Now

    What is the Table Module Design Pattern?

    The Table Module Pattern is an enterprise domain logic pattern from Martin Fowler’s Patterns of Enterprise Application Architecture (PofEAA).

    In simple terms: A Table Module organizes domain logic with one class per database table or view, where a single instance of that class contains all the procedures and business rules that act on the table's data.

    Real-World Example: Hotel Room Reservation System

    Consider a database schema for booking hotel rooms with three primary tables:

    • Hotel Table: Stores hotel records (e.g., hotel_id, hotel_name).
    • Room Table: Stores room records (e.g., room_id, room_number, number_of_beds).
    • Booking Table: Stores booking records (e.g., booking_id, hotel_id, room_id, is_booked).

    Under the Table Module pattern, you define one dedicated module class for each database table:

    • Hotel Module Class: Handles all queries, updates, insertions, and business logic for all rows in the Hotel table.
    • Room Module Class: Handles room availability checks, updates, and modifications across the entire Room table.
    • Booking Module Class: Encapsulates booking reservations, room assignment checks, and cancellations across the Booking table.

    Key Characteristics & When to Use

    • One Class Per Table: Maps business logic directly to table schemas instead of creating individual entity instances per row.
    • Record Set Integration: Pairs naturally with tabular data structures such as Record Sets or DataSets.
    • No Inheritance Support: Unlike rich Domain Models, Table Modules do not support object-oriented inheritance relationships.
    • Best Suited For: Applications where business logic is moderately simple and structured strictly around relational tables.

    Recommended Design Pattern Tutorials:


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

    Click the below Image to Enlarge
    Table Module Design Pattern















    See also:

  • All Design Patterns Links
  • Tutorials