← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Table Module Pattern

quality Intermediate

Also Known As

table module

TL;DR

One class per database table handling all logic — a pragmatic middle ground between Transaction Script and full Domain Model.

Explanation

Table Module (Martin Fowler, PoEAA): all business logic for a table's rows in one class, operating on collections not individual objects. Good for: moderate business logic that outgrows Transaction Script but does not justify full Domain Model.

Common Misconception

Table Module is the same as Repository — Repository returns domain objects one at a time; Table Module works on the table as a unit.

Why It Matters

Table Module fits database-centric applications where the domain logic is thin and SQL is the natural expression of business rules. It avoids the object-relational impedance mismatch of Active Record for read-heavy reporting use cases. The limitation is that it becomes awkward when business logic complexity grows — the module accumulates methods that would be better distributed across domain objects. It works well as an intermediate step when migrating from procedural database code toward a richer domain model.

Common Mistakes

  • Growing into a God Class
  • Mixing data access with presentation
  • One per every table regardless of need

Code Examples

✗ Vulnerable
// Logic scattered across files:
// file1.php: $pdo->query('SELECT * FROM orders WHERE...');
// file2.php: $pdo->query('UPDATE orders SET...');
✓ Fixed
class OrderTable {
    public function findPendingOverdue(): array { return $this->db->query(...)->fetchAll(); }
    public function markAsProcessing(int $id): void { $this->validateTransition($id); $this->db->execute(...); }
}

Added 16 Mar 2026
Edited 23 Mar 2026
Views 19
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 3 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 1 ping F 1 ping S
Amazonbot 6 ChatGPT 3 Perplexity 2 Unknown AI 2 Google 2 Ahrefs 2 Bing 1
crawler 15 crawler_json 3
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: Medium
⚡ Quick Fix
Use the Table Module pattern for simple domain logic where an Active Record is overkill but a full Domain Model is unnecessary — one class handles all business logic for a database table
📦 Applies To
any web cli
🔗 Prerequisites
🔍 Detection Hints
Large Eloquent model with 50+ methods; Active Record with complex business logic mixed with persistence; needed separation between domain logic and database
Auto-detectable: ✗ No phpstan deptrac
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: Medium Context: Class Tests: Update

✓ schema.org compliant