Interface Segregation
Java Example
Bad Design (Violating ISP)
interface Worker {
void work();
void eat();
}
class Robot implements Worker {
public void work() {
System.out.println("Robot working...");
}
public void eat() { // Robots don't eat, but are forced to implement this method.
throw new UnsupportedOperationException("Robots don't eat");
}
}Good Design (Following ISP)
Python Example
Bad Design (Violating ISP)
Good Design (Following ISP)
Last updated