Skip to content
Low Level Design Mastery Logo
LowLevelDesign Mastery

Interface Segregation Principle

Clients should not be forced to depend on methods they don't use.

The Interface Segregation Principle (ISP) states that clients should not be forced to depend on interfaces they don’t use. Instead of one fat interface, many small, specific interfaces are preferred.

This principle helps prevent the creation of “fat” or “bloated” interfaces that force implementing classes to provide empty implementations for methods they don’t need.

Diagram

The Interface Segregation Principle ensures that:

  • Interfaces are focused - Each interface has a single, well-defined purpose
  • No forced implementations - Classes don’t implement methods they don’t need
  • Better cohesion - Related methods are grouped together
  • Loose coupling - Clients depend only on what they actually use

In simple terms: Don’t force a class to implement methods it doesn’t need!

Consider a system with different types of workers. Let’s see what happens when we create a fat interface.

Diagram
Diagram

Why this follows ISP:

  • Each interface has a single, focused responsibility
  • Classes implement only the interfaces they need
  • No empty implementations or exceptions
  • Changes to one interface don’t affect unrelated classes

Consider a document management system with different types of devices that can interact with documents.

Diagram
Diagram

Why this follows ISP:

  • Each interface represents a single capability
  • Devices implement only the interfaces they support
  • No empty implementations or exceptions
  • Type system prevents calling unsupported methods
  • Easy to add new capabilities without affecting existing devices

Remember: The Interface Segregation Principle ensures that classes only depend on methods they actually use, leading to cleaner and more maintainable code! 🎯

💡 Time to Practice!

Now that you understand the concepts, put them into practice with our interactive playground. Build UML diagrams, write code, and get AI-powered feedback.

Browse All Problems