OOP · SOLID Principles
Interface Segregation Principle (ISP)
Encourages better object-oriented design.
- Encourages better object-oriented design.
Best Practices
- Override methods without changing their expected behavior.
- Ensure child classes satisfy the parent's contract.
- Use inheritance only for true "is-a" relationships.
- Prefer composition when behavior differs significantly.
- Test subclasses wherever the parent is used.
Common Mistakes
- Throwing UnsupportedOperationException in overridden methods.
- Creating subclasses that cannot perform the parent's operations.
- Using inheritance only for code reuse.
- Breaking parent class assumptions.
- Violating behavioral compatibility.
Real-World Problem
Imagine you're developing a Restaurant Management System. Initially, the restaurant has only dine-in customers, so an interface called RestaurantService contains methods for taking orders, serving food, and processing payments.
As the business expands, the restaurant introduces Online Delivery and Takeaway services. Developers make every service implement the same interface. However, delivery services don't serve food at tables, and takeaway services don't require table service either. Despite this, all classes are forced to implement every method in the interface.
Over time, several classes contain empty or unnecessary method implementations, making the design confusing and harder to maintain.
Problem The RestaurantService interface contains methods that are not required by every implementation. Classes are forced to implement methods they never use, often leaving them empty or throwing exceptions. This results in unnecessary code, poor readability, and interfaces that become larger as new requirements are added.
Pain Points Classes are forced to implement methods they do not need. This leads to empty or meaningless implementations, making the codebase harder to understand and maintain. As interfaces grow larger, every implementation becomes more complex, increasing the effort required to develop, test, and modify the application.
Solution
The Interface Segregation Principle states that clients should not be forced to depend on methods they do not use. Instead of creating one large interface, divide it into multiple small, focused interfaces. Each class should implement only the interfaces that match its responsibilities .

Java Program 1 – ISP Violation

Java Program 2 – ISP Applied

Prefer many small role-interfaces over one fat interface clients are forced to implement.
// BAD: interface Worker { void work(); void eat(); } — a Robot can't eat()
// GOOD: split into focused capabilities
interface Workable { void work(); }
interface Feedable { void eat(); }
class Human implements Workable, Feedable {
public void work() { System.out.println("Working"); }
public void eat() { System.out.println("Eating"); }
}
class Robot implements Workable { // implements only what it needs
public void work() { System.out.println("Working 24/7"); }
}