{
    "slug": "interface_segregation",
    "term": "Interface Segregation Principle",
    "category": "quality",
    "difficulty": "intermediate",
    "short": "Clients should not be forced to depend on interfaces they do not use — prefer many small, focused interfaces over one large one.",
    "long": "The I in SOLID, ISP states that a class implementing an interface should not be forced to implement methods it doesn't use. Fat interfaces that bundle unrelated methods force implementors to provide stub implementations for irrelevant methods. The solution is to split large interfaces into smaller, cohesive ones and have classes implement only what they need. This complements the Dependency Inversion Principle — depend on the narrowest interface needed for the task.",
    "aliases": [
        "ISP",
        "Interface Segregation Principle",
        "fat interface"
    ],
    "tags": [
        "solid",
        "oop",
        "principles"
    ],
    "misconception": "One large interface is simpler to manage than many small ones. A large interface forces implementors to stub out methods they do not use, creating misleading no-op implementations and tight coupling to functionality the implementor does not need.",
    "why_it_matters": "The Interface Segregation Principle prevents classes from being forced to implement methods they don't use — large interfaces create fake implementations and hide which capability is actually needed.",
    "common_mistakes": [
        "One large repository interface with 20 methods — every implementation must stub 15 unused ones.",
        "Adding new methods to an existing interface instead of extending it — breaks all implementors.",
        "Not splitting interfaces at natural capability boundaries — Readable, Writable, Listable rather than FileRepository.",
        "Confusing ISP with SRP — ISP is about interface design, SRP is about class responsibility."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "solid",
        "interfaces",
        "single_responsibility"
    ],
    "prerequisites": [
        "solid",
        "interfaces",
        "dependency_injection"
    ],
    "refs": [
        "https://en.wikipedia.org/wiki/Interface_segregation_principle"
    ],
    "bad_code": "interface Worker {\n    public function work(): void;\n    public function eat(): void;   // robots don't eat!\n    public function sleep(): void; // robots don't sleep!\n}\n\nclass RobotWorker implements Worker {\n    public function eat(): void  { throw new \\Exception('Robots do not eat'); }\n    public function sleep(): void { throw new \\Exception('Robots do not sleep'); }\n}",
    "good_code": "interface Workable  { public function work(): void; }\ninterface Feedable  { public function eat(): void; }\ninterface Restable  { public function sleep(): void; }\n\nclass HumanWorker  implements Workable, Feedable, Restable { ... }\nclass RobotWorker  implements Workable { ... }",
    "quick_fix": "Split fat interfaces into small focused ones — clients should only implement what they actually use; a class implementing an interface with unused methods is a sign of violation",
    "severity": "medium",
    "effort": "medium",
    "created": "2026-03-15",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/interface_segregation",
        "html_url": "https://codeclaritylab.com/glossary/interface_segregation",
        "json_url": "https://codeclaritylab.com/glossary/interface_segregation.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": "[Interface Segregation Principle](https://codeclaritylab.com/glossary/interface_segregation) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/interface_segregation"
            }
        }
    }
}