{
    "slug": "low_cohesion",
    "term": "Low Cohesion",
    "category": "quality",
    "difficulty": "intermediate",
    "short": "A class or module that does many unrelated things — high coupling's counterpart, making code hard to understand, test, and reuse.",
    "long": "Cohesion measures how closely related the responsibilities of a module are. High cohesion: a class does one thing and all its methods work toward that single purpose. Low cohesion: a class mixes unrelated concerns — a UserService that also sends emails, processes payments, and generates PDF reports. Low cohesion is often the root cause of the God Class smell. The fix is decomposition: extract responsibilities into focused classes, guided by the Single Responsibility Principle.",
    "aliases": [
        "low cohesion",
        "mixed responsibilities",
        "lack of cohesion"
    ],
    "tags": [
        "quality",
        "oop",
        "solid",
        "design"
    ],
    "misconception": "Putting related functionality in one place always increases cohesion — cohesion is about shared purpose, not physical proximity; a class handling both user authentication and email formatting has low cohesion even though both involve users.",
    "why_it_matters": "Low cohesion classes are impossible to reuse — you cannot use the email functionality without pulling in the payment logic — and testing one responsibility requires setting up all the others.",
    "common_mistakes": [
        "Adding utility methods to existing classes because it is convenient — create a dedicated utility class instead.",
        "Service classes that grow unbounded — UserService should not handle billing, reporting, and notifications.",
        "Static helper classes with dozens of unrelated methods — a sign of dumping ground design.",
        "Confusing low coupling (few dependencies) with high cohesion — they are independent dimensions."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "cohesion",
        "single_responsibility",
        "god_class",
        "coupling"
    ],
    "prerequisites": [
        "cohesion",
        "cohesion_types",
        "single_responsibility"
    ],
    "refs": [
        "https://en.wikipedia.org/wiki/Cohesion_(computer_science)"
    ],
    "bad_code": "// Low cohesion — UserService does everything:\nclass UserService {\n    public function register(array $data): User { /* ... */ }\n    public function sendWelcomeEmail(User $u): void { /* ... */ }\n    public function generateInvoicePdf(User $u): string { /* ... */ }\n    public function processSubscriptionPayment(User $u): void { /* ... */ }\n    public function exportUsersToCsv(): string { /* ... */ }\n}",
    "good_code": "// High cohesion — each class has one purpose:\nclass UserRegistrationService {\n    public function register(array $data): User { /* ... */ }\n}\nclass UserEmailService {\n    public function sendWelcomeEmail(User $u): void { /* ... */ }\n}\nclass InvoiceGenerator {\n    public function generate(User $u): string { /* ... */ }\n}\nclass SubscriptionPaymentService {\n    public function charge(User $u): void { /* ... */ }\n}",
    "quick_fix": "Look for methods that use completely different instance variables — each group of methods using the same data is a candidate for extraction into its own class",
    "severity": "medium",
    "effort": "high",
    "created": "2026-03-16",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/low_cohesion",
        "html_url": "https://codeclaritylab.com/glossary/low_cohesion",
        "json_url": "https://codeclaritylab.com/glossary/low_cohesion.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": "[Low Cohesion](https://codeclaritylab.com/glossary/low_cohesion) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/low_cohesion"
            }
        }
    }
}