Article

Interface Segregation: Small is Beautiful

Clients should not be forced to depend on methods they do not use. Split large interfaces into smaller ones.

SOLIDISPInterfaces

The Interface Segregation Principle (ISP) is about keeping interfaces lean and focused. A client should never be forced to implement an interface that contains methods it doesn't need.

The Danger of 'Fat' Interfaces

When you have a 'Worker' interface that includes work() and eat(), and you have a Robot implementation, the Robot is forced to implement a dummy eat() method. This is a sign that the interface is too broad.

Segregation for Decoupling

By splitting the interface into Workable and Feedable, the Robot only implements Workable. This keeps your code cleaner and prevents unnecessary dependencies from blooming across your project.

About the writer

Decoupled Editorial

Engineering Practices

Recommended by our partners

Discussion

Keep the conversation going

Log in to join the discussion.

No comments yet. The first thoughtful reply can set the tone for the whole thread.