{
    "slug": "lazy_class",
    "term": "Lazy Class",
    "category": "quality",
    "difficulty": "beginner",
    "short": "A class that doesn't do enough to justify its existence — the cost of understanding it exceeds the value it provides.",
    "long": "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.",
    "aliases": [
        "lazy class smell",
        "unnecessary class",
        "under-used class"
    ],
    "tags": [
        "code-smell",
        "refactoring",
        "yagni"
    ],
    "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."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "code_smell",
        "single_responsibility"
    ],
    "prerequisites": [
        "single_responsibility",
        "speculative_generality",
        "yagni"
    ],
    "refs": [
        "https://refactoring.guru/smells/lazy-class"
    ],
    "bad_code": "// Class with a single trivial method — doesn't justify its existence\nclass StringHelper {\n    public function upper(string \\$s): string { return strtoupper(\\$s); }\n}",
    "good_code": "// Just call strtoupper() directly\n// A class is justified when it encapsulates state + meaningful behaviour:\nclass CurrencyFormatter {\n    public function __construct(private string \\$locale, private string \\$currency) {}\n    public function format(int \\$cents): string {\n        return NumberFormatter::create(\\$this->locale, NumberFormatter::CURRENCY)\n            ->formatCurrency(\\$cents / 100, \\$this->currency);\n    }\n}",
    "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",
    "severity": "low",
    "effort": "low",
    "created": "2026-03-15",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/lazy_class",
        "html_url": "https://codeclaritylab.com/glossary/lazy_class",
        "json_url": "https://codeclaritylab.com/glossary/lazy_class.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[Lazy Class](https://codeclaritylab.com/glossary/lazy_class) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/lazy_class"
            }
        }
    }
}