Tag: Liskov Substitution Principle (LSP)


  • Interface Segregation Principle (ISP)

    Clients should not be obligated to rely on interfaces they don’t utilize. Example: Consider an interface that imposes irrelevant 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”);…

  • Open/Closed Principle (OCP)

    Software entities should be open for extension but closed for modification. Example: Let’s say you have a class that calculates the area of different shapes. // Violation of OCP public class AreaCalculator { public double calculateArea(Object shape) { if (shape instanceof Circle) { Circle circle = (Circle) shape; return Math.PI * circle.getRadius() * circle.getRadius(); }…