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

Lazy Class

quality Beginner

Also Known As

lazy class smell unnecessary class under-used class

TL;DR

A class that doesn't do enough to justify its existence — the cost of understanding it exceeds the value it provides.

Explanation

Lazy Class is the inverse of God Class: a class so small or trivial that it adds complexity without adding value. It may be the remnant of planned functionality that was never completed, or a class created through over-engineering that could simply be a method, a constant, or data on another class. The fix is either to inline the class into its caller (if it has one consumer) or to merge it with a related class that would benefit from its functionality.

Common Misconception

Every abstraction justifies its own class. A class that does so little it barely earns its existence adds navigation overhead — if its logic would fit clearly inside the caller or a simpler structure, collapse it.

Why It Matters

A class that does too little to justify its existence adds indirection without value — it increases the number of files developers must understand without providing meaningful abstraction.

Common Mistakes

  • Creating a class to wrap a single function call — a plain function or static method is clearer.
  • Abstract classes with only one concrete subclass — inline the subclass or make the abstract concrete.
  • Data transfer objects that are never validated or enriched — use an array or typed array instead.
  • Classes created 'for future extensibility' without a current use case — YAGNI applies.

Code Examples

✗ Vulnerable
// Class with a single trivial method — doesn't justify its existence
class StringHelper {
    public function upper(string \$s): string { return strtoupper(\$s); }
}
✓ Fixed
// Just call strtoupper() directly
// A class is justified when it encapsulates state + meaningful behaviour:
class CurrencyFormatter {
    public function __construct(private string \$locale, private string \$currency) {}
    public function format(int \$cents): string {
        return NumberFormatter::create(\$this->locale, NumberFormatter::CURRENCY)
            ->formatCurrency(\$cents / 100, \$this->currency);
    }
}

Added 15 Mar 2026
Edited 22 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 0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 2 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 2 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S
No pings yet today
Amazonbot 7 Google 4 Perplexity 2 Majestic 1 Ahrefs 1
crawler 12 crawler_json 3
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Inline the lazy class into its only caller — a class that does too little doesn't justify the abstraction overhead; merge thin wrappers that add no value
📦 Applies To
any web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Class with only one method and one caller; wrapper class that just delegates with no transformation; PHP class with only 5-10 lines doing nothing interesting
Auto-detectable: ✗ No phpmd phpstan
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✓ Auto-fixable Fix: Low Context: Class Tests: Update

✓ schema.org compliant