August 12, 2024August 19, 2024 Interface Segregation Principle (ISP) Clients should not be forced to depend on interfaces they do not use. Example: Imagine an interface that enforces unnecessary methods on implementing classes. // Violation of ISP public interface Worker { void work(); void eat(); } public class HumanWorker implements Worker { public void work() { System.out.println("Human working"); } public void eat() { System.out.println("Human eating"); } } public class RobotWorker implements Worker { public void work() { System.out.println("Robot working"); } public void eat() { // Robots don't eat } } // Following ISP public interface Workable { void work(); } public interface Eatable { void eat(); } public class HumanWorker implements Workable, Eatable { public void work() { System.out.println("Human working"); } public void eat() { System.out.println("Human eating"); } } public class RobotWorker implements Workable { public void work() { System.out.println("Robot working"); } } Here, RobotWorker doesn’t need to implement eat(), respecting the ISP. Previous: Liskov Substitution Principle (LSP) Next: Dependency Inversion Principle (DIP) SOLID Solid Design Principle Dependency Inversion Principle (DIP)Interface Segregation Principle (ISP)Liskov Substitution Principle (LSP)solid