Interface Segregation Principle: Why Smaller Interfaces Make Better Code
The Interface Segregation Principle (ISP), part of the SOLID design principles, states that no class should be forced to depend on methods it does not use. Instead of creating one large, rigid interface, developers should break it into smaller, focused contracts that classes implement only as needed. A practical example illustrates this with a blog system where a standard user and an admin user require different capabilities, making a single shared interface problematic. By segregating interfaces, changes to one contract — such as admin ban rules — do not affect unrelated classes like a standard user. This approach results in more modular, maintainable, and loosely coupled code.
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