Interface Segregation Principle: Why Smaller Interfaces Make Better Code
The Interface Segregation Principle (ISP), part of the SOLID design guidelines, states that no class should be forced to depend on methods it does not use. A common violation occurs when a single large interface bundles unrelated behaviors, compelling classes to implement irrelevant or nonsensical methods. For example, a blog system that assigns a single interface to all users would force a standard user to implement an admin-only ban function. The recommended solution is to break large interfaces into smaller, focused contracts so each class implements only what it genuinely needs. This approach keeps codebases modular, reduces unnecessary coupling, and ensures that changes to one interface do not affect unrelated classes.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in