Table Module Pattern
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(...); }
}
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
16 Mar 2026
Edited
23 Mar 2026
Views
19
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 1
Amazonbot 6
ChatGPT 3
Perplexity 2
Unknown AI 2
Google 2
Ahrefs 2
Bing 1
How they use it
crawler 15
crawler_json 3
Related categories
⚡
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
🔍 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