Showing posts with label Transaction Script. Show all posts
Showing posts with label Transaction Script. 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
  • Transaction Script 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 Transaction Script Design Pattern?

    The Transaction Script Pattern is one of the most fundamental domain logic patterns introduced in Martin Fowler’s Patterns of Enterprise Application Architecture (PofEAA).

    In simple terms: A Transaction Script organizes business logic into procedures where each procedure handles a single request from the presentation tier.

    Real-World Example: Booking a Hotel Room

    Imagine a client visiting your website to book hotel room number 142. Using the Transaction Script pattern, you write a single procedure—let's call it bookHotelRoom()—that executes the entire business transaction from start to finish:

    • Step 1 (Check Availability): Query the database to verify if room 142 is vacant for the chosen dates.
    • Step 2 (Price Calculation): Compute the total booking fee, including taxes and discounts.
    • Step 3 (Payment Processing): Accept payment from the client.
    • Step 4 (Database Update): Mark room 142 as booked in the database.
    • Step 5 (Commit Transaction): Commit the database transaction so the reservation is permanently saved.

    Key Advantages of Transaction Script

    • Simplicity: It is straightforward to understand and implement without needing complex object models.
    • Low Overhead: Perfect for small applications or applications where business logic is mostly CRUD operations.
    • Direct Database Access: Plays well with thin database wrappers like Table Data Gateway or Row Data Gateway.

    Recommended Design Pattern Tutorials:


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

    Click the below Image to Enlarge
    Transaction Script Design Pattern















    See also:

  • All Design Patterns Links
  • Tutorials